[SRU] JAVA_HOME auto-detection fails due to whitespace in update-java-alternatives output

Bug #1556997 reported by Václav Šmilauer
110
This bug affects 19 people
Affects Status Importance Assigned to Milestone
One Hundred Papercuts
Fix Released
Medium
Unassigned
imagej (Debian)
Fix Released
Unknown
imagej (Ubuntu)
Fix Released
Medium
Unassigned
Xenial
Fix Released
Undecided
Unassigned
Yakkety
Fix Released
Undecided
Unassigned
Zesty
Fix Released
Medium
Unassigned

Bug Description

[Impact]

 * running imagej with auto detected JAVA_HOME fails

[Test Case]

 * run it

[Regression Potential]

 * none, this is a bug because update-java-alternatives has a whitespace in its output, and parsing fails

[Other Info]

Running imagej fails with the following message:

   Open other images in this ImageJ panel as follows:
     imagej -p 3 <image1> [<image2> ... <imageN>]

   No JVM found to run ImageJ
   Please apt-get install a JVM to run ImageJ or
   set JAVA_HOME if it's not a JVM from a Debian Package.

even though multiple JVM's are installed here.

The problem is that the /usr/bin/imagej script detects JAVA_HOME using

   JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk | sort | tail -1 | cut -d' ' -f 3)

which is empty as the output of update-java-alternatives -l is (note multiple spaces between columns):

java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64

and cut -d' ' -f3 selects space. The solution is to squeeze multiple spaces before running cut, so the line should read:

   JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk | sort | tail -1 | tr -s ' ' | cut -d' ' -f 3)

which then gives the correct output (/usr/lib/jvm/java-1.8.0-openjdk-amd64 in my case) and makes imagej run as expected.

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: imagej 1.50d+dfsg-1
ProcVersionSignature: Ubuntu 3.19.0-49.55-lowlatency 3.19.8-ckt12
Uname: Linux 3.19.0-49-lowlatency x86_64
NonfreeKernelModules: btrfs ufs qnx4 hfsplus hfs minix ntfs msdos jfs xfs libcrc32c pci_stub binfmt_misc cfg80211 joydev hid_logitech_hidpp snd_hda_codec_hdmi snd_hda_intel snd_hda_controller eeepc_wmi asus_wmi sparse_keymap snd_hda_codec x86_pkg_temp_thermal intel_powerclamp video snd_hwdep snd_pcm snd_seq_midi kvm_intel snd_seq_midi_event kvm snd_rawmidi crct10dif_pclmul snd_seq crc32_pclmul snd_seq_device snd_timer snd aesni_intel sb_edac aes_x86_64 lrw soundcore gf128mul glue_helper edac_core ablk_helper serio_raw mei_me cryptd mei lpc_ich tpm_infineon 8250_fintek shpchp mac_hid nct6775 hwmon_vid coretemp parport_pc ppdev nfsd lp auth_rpcgss nfs_acl lockd grace sunrpc parport autofs4 raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx xor raid6_pq raid0 multipath linear hid_logitech_dj usbhid hid raid1 amdkfd amd_iommu_v2 mxm_wmi radeon igb ttm drm_kms_helper dca psmouse ptp drm ahci pps_core libahci i2c_algo_bit wmi
ApportVersion: 2.20-0ubuntu3
Architecture: amd64
CurrentDesktop: XFCE
Date: Mon Mar 14 15:56:23 2016
PackageArchitecture: all
SourcePackage: imagej
UpgradeStatus: Upgraded to xenial on 2012-03-12 (1463 days ago)

Revision history for this message
Václav Šmilauer (eudoxos) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in imagej (Ubuntu):
status: New → Confirmed
Revision history for this message
Éric Piel (Delmic) (piel) wrote :

This bug has been reported also in debian, as bug #820097. (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=820097)...
and fixed. The fixed version is already available for the next Ubuntu (Yakkety), in version 1.50i+dfsg-1. So maybe importing that newer version in Xenial would be fine.

Alternatively, the fix is a one line patch:
--- imagej-1.50d+dfsg/debian/imagej.sh 2014-03-12 12:58:36.000000000 +0000
+++ imagej-1.50i+dfsg/debian/imagej.sh 2016-04-07 12:57:41.000000000 +0000
@@ -29,7 +29,7 @@

 if [ -z "$JAVA_HOME" ] ; then
     # This does not work see #505315
- JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk | sort | tail -1 | cut -d' ' -f 3)
+ JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk | sort | tail -1 | tr -s ' ' | cut -d' ' -f 3)
     # Reverted to old version - see #558222 (Andreas Tille)
     # JAVA_HOME=$(dirname $(dirname $(dirname $(readlink /etc/alternatives/java))))
     # Also suggested by From: JR Coding <email address hidden>; To: <email address hidden>

Changed in imagej (Ubuntu):
importance: Undecided → Medium
Changed in hundredpapercuts:
status: New → Confirmed
importance: Undecided → Medium
Changed in imagej (Debian):
status: Unknown → Fix Released
Revision history for this message
Vincent Gerris (vgerris) wrote :

I encountered this ad well.
In my case the workaround was :
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
and then start it fromthe command line.

Since a fix is released according to the tracker here, what needs to happen to get it built and released?

Revision history for this message
Vincent Gerris (vgerris) wrote :

Just verified this build works:
https://launchpad.net/ubuntu/+source/imagej/1.50i+dfsg-1/+build/9642507

Download and install with software center.
So plus 1 for just applying the same fix.

Revision history for this message
Amr Ibrahim (amribrahim1987) wrote :

The fix should be SRU'ed into Xenial.

Revision history for this message
Vincent Gerris (vgerris) wrote :

Amr, I have no clue what you mean with that comment.
Can you explain what you mean and make that happen?
thank you

Revision history for this message
Nish Aravamudan (nacc) wrote :

@Vincent, please review: https://wiki.ubuntu.com/StableReleaseUpdates especially the section under "Procedure".

Revision history for this message
David Marçal (davidufg) wrote :

I have this problem of setting JAVA_HOME too using Kubuntu 16.10 and linux mint 18 kde. To solve I edit /usr/bin/imagej putting JAVA_HOME=/usr/lib/jvm/default-java

################DEFINE JAVA_HOME #############################

if [ -z "$JAVA_HOME"] ; then
    # This does not work see#505315
    # JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk ...
    # Reverted to old version ....
    # JAVA_HOME=$(dirname $(dirname ......
    # Also suggested by From: JR Coding....
    # JAVA_HOME=$(readlink -f ...
    # however, this has the same problem
      JAVA_HOME=/usr/lib/jvm/default-java
fi

This works for me.

Revision history for this message
VanillaMozilla (vanillamozilla) wrote :

Éric Piel (Delmic) (piel) wrote:
- JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk | sort | tail -1 | cut -d' ' -f 3)
+ JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk | sort | tail -1 | tr -s ' ' | cut -d' ' -f 3)

Confirming that this works on my Ubuntu 16.04 32 bit system.

The program is completely unusable (won't start) in 16.04, and it only affects this one program, so yes, Xenial should be patched ASAP.

For the long term, shouldn't there be a simpler way to point to the default JVM?

Changed in imagej (Ubuntu):
status: Confirmed → Fix Released
summary: - JAVA_HOME auto-detection fails due to whitespace in update-java-
+ [SRU] JAVA_HOME auto-detection fails due to whitespace in update-java-
alternatives output
Changed in imagej (Ubuntu Yakkety):
status: New → Fix Committed
Changed in imagej (Ubuntu Xenial):
status: New → Fix Committed
Changed in imagej (Ubuntu Yakkety):
status: Fix Committed → Fix Released
Revision history for this message
Gianfranco Costamagna (costamagnagianfranco) wrote :

please test ppa:costamagnagianfranco/locutusofborg-ppa

description: updated
Revision history for this message
Brian Murray (brian-murray) wrote : Please test proposed package

Hello Václav, or anyone else affected,

Accepted imagej into xenial-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/imagej/1.50d+dfsg-1ubuntu1.16.04.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed.Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, and change the tag from verification-needed to verification-done. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

tags: added: verification-needed
Changed in hundredpapercuts:
status: Confirmed → Fix Released
Revision history for this message
Gianfranco Costamagna (costamagnagianfranco) wrote :

@Václav can you please test it?

Revision history for this message
Gianfranco Costamagna (costamagnagianfranco) wrote :

runs correctly on my xenial

tags: added: verification-done
removed: verification-needed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package imagej - 1.50d+dfsg-1ubuntu1.16.04.1

---------------
imagej (1.50d+dfsg-1ubuntu1.16.04.1) xenial; urgency=medium

   * Backport patch to xenial
   * Fix wrapper script (thanks for the patch to Kai Wohlfahrt
     <email address hidden>)
     Closes: #820097 LP: #1556997

 -- Gianfranco Costamagna <email address hidden> Tue, 28 Feb 2017 12:52:49 +0100

Changed in imagej (Ubuntu Xenial):
status: Fix Committed → Fix Released
Revision history for this message
Brian Murray (brian-murray) wrote : Update Released

The verification of the Stable Release Update for imagej has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.