gradle scrpt breaks JAVA_HOME environment setting

Bug #1646623 reported by Systems Test
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gradle (Ubuntu)
New
Undecided
Unassigned

Bug Description

The script at:
> ls -l /usr/share/gradle/bin/gradle
-rwxr-xr-x 1 root root 5114 Sep 9 2013 /usr/share/gradle/bin/gradle

incorretly overrides the setting of the JAVA_HOME environment variable at line 70. Simply assuming it's OK to override JAVA_HOME is bad form. Also, why check in the very next line if it's been set? It looks like someone added duct tape with that export statement. At the very least, it shold NOT alter the value if it was set priror to runnig the script. e.g. someting like:

```
> diff /usr/share/gradle/bin/gradle /usr/share/gradle/bin/gradle.PATCHED
70c70
< export JAVA_HOME=/usr/lib/jvm/default-java
---
> export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/default-java}
```

Snip from /usr/share/gradle/bin/gradle starting at line 70:

```
export JAVA_HOME=/usr/lib/jvm/default-java

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
        # IBM's JDK on AIX uses strange locations for the executables
        JAVACMD="$JAVA_HOME/jre/sh/java"
    else
        JAVACMD="$JAVA_HOME/bin/java"
    fi
    if [ ! -x "$JAVACMD" ] ; then
        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
    fi
else
    JAVACMD="java"
    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
```

ProblemType: Bug
DistroRelease: Ubuntu 14.04
Package: gradle 1.4-2ubuntu1
ProcVersionSignature: Ubuntu 3.13.0-103.150-generic 3.13.11-ckt39
Uname: Linux 3.13.0-103-generic x86_64
ApportVersion: 2.14.1-0ubuntu3.21
Architecture: amd64
Date: Thu Dec 1 21:05:57 2016
Ec2AMI: ami-9a29cea9
Ec2AMIManifest: (unknown)
Ec2AvailabilityZone: us-west-2c
Ec2InstanceType: c3.large
Ec2Kernel: unavailable
Ec2Ramdisk: unavailable
PackageArchitecture: all
SourcePackage: gradle
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Systems Test (allpoints) wrote :
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.