Issue1125

classification
Title: not valid JAVA_HOME path
Type: Severity: normal
Components: None Versions: 2.5alpha1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: otmarhumbel Nosy List: foripperz, fwierzbicki, mr_tines, otmarhumbel
Priority: Keywords:

Created on 2008-09-10.16:04:29 by foripperz, last changed 2008-11-05.15:39:42 by otmarhumbel.

Files
File name Uploaded Description Edit Remove
jython.bat foripperz, 2008-09-10.16:04:28 patched file
test_empty.bat otmarhumbel, 2008-10-14.12:39:36 method to safely test a string for emptiness
jython.bat.log otmarhumbel, 2008-10-15.08:21:18 output of the new .bat file
Messages
msg3497 (view) Author: foripperz (foripperz) Date: 2008-09-10.16:04:27
in jython 2.5a2, "jython.bat" have this line(like this..), 
set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_10"

but, it is not valid, because window shell cannot read "space" in <"..">

so, edit it...
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_10      (delete '"')
msg3511 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2008-09-13.17:32:01
This looks to me like it is the reverse of a fix by Oti -- I've assigned
this to him since I think he understands better than I do.
msg3602 (view) Author: Oti Humbel (otmarhumbel) Date: 2008-09-15.21:43:28
foripperz: as of alpha3, we fixed the jython.bat file so that it can 
handle a JAVA_HOME like described in msg3497.
Please give alpha3 a try, and report the error in case there still is one.
Thanks!
msg3621 (view) Author: Mr. Tines (mr_tines) Date: 2008-09-24.17:17:51
I've tripped over something like this in 2.5a3 as well -- my workround
is to add quotes into the jython.bat text like

if not "[%JAVA_HOME%]" == "[]" (

in both lines 20 and 87; otherwise you get

"Files\Java\jdk1.6.0] was unexpected at this time."
msg3622 (view) Author: Oti Humbel (otmarhumbel) Date: 2008-09-25.11:35:49
Mr. Tines,

thanks for reporting!

To be able to understand what's going on, could you please change line 1
and line 8 of the jython.bat from
  @echo off
to
  rem @echo off
, reproduce the error, and post the console output here?

Thanks a lot!
Oti.
msg3624 (view) Author: Mr. Tines (mr_tines) Date: 2008-09-26.17:57:11
Pretty simple, really -- the space in the "if" statement is taken as a
token delimiter because it is not enquoted.

>c:\jython2.5a3\bin\jython.bat
>rem @echo off
>rem
---------------------------------------------------------------------------
>rem jython.bat - start script for Jython (adapted from jruby.bat)
>rem
>rem Environment variables (optional)
>rem
>rem   JAVA_HOME      Java installation directory
>rem
>rem   JYTHON_HOME    Jython installation directory
>rem
>rem   JYTHON_OPTS    Default Jython command line arguments
>rem
>rem
---------------------------------------------------------------------------
>setlocal enabledelayedexpansion
>rem ----- Verify and set required environment variables
-----------------------
>set _JAVA_CMD=java
Files\Java\jdk1.6.0] was unexpected at this time.
>if not [C:\Program Files\Java\jdk1.6.0] == [] (
>

If you enquote line 20 only, then jython.bat --help goes on to do the
same at line 87

>if not [C:\Program Files\Java\jdk1.6.0] == [] (
>c:\jython2.5a3\bin\jython.bat --help
>rem @echo off
>rem
---------------------------------------------------------------------------
>rem jython.bat - start script for Jython (adapted from jruby.bat)
>rem
>rem Environment variables (optional)
>rem
>rem   JAVA_HOME      Java installation directory
>rem
>rem   JYTHON_HOME    Jython installation directory
>rem
>rem   JYTHON_OPTS    Default Jython command line arguments
>rem
>rem
---------------------------------------------------------------------------
>setlocal enabledelayedexpansion
>rem ----- Verify and set required environment variables
-----------------------
>set _JAVA_CMD=java
>if not "[C:\Program Files\Java\jdk1.6.0]" == "[]
" (set _JAVA_CMD="C:\Program Files\Java\jdk1.6.0\bin\java" )
>set _JYTHON_HOME=
>if not "[]" == "[]" goto gotHome
>pushd "c:\jython2.5a3\bin\\.."
C:\jython2.5a3>set _JYTHON_HOME="C:\jython2.5a3"
C:\jython2.5a3>popd
>if not exist "C:\jython2.5a3"\jython.jar goto tryComplete
>set _CP="C:\jython2.5a3"\jython-complete.jar
>if exist "C:\jython2.5a3"/jython-complete.jar goto run
>set _JAVA_STACK=-Xss512k
>rem Escape any quotes. Use _S for ', _D for ", and _U to escape _ itself.
>rem We have to escape _ itself, otherwise file names with _S and _D
>rem will be converted to to wrong ones, when we un-escape. See JRUBY-2821.
>set _ARGS=--help
>if not defined _ARGS goto argsDone
>set _ARGS=--help
>set _ARGS=--help
>set _ARGS=--help
>set _ARGS="--help"
>rem split args by spaces into first and rest
>for /F "tokens=1,*" %i in ("--help") do call :getArg "%i" "%j"
>call :getArg "--help" ""
>rem remove quotes around first arg
>for %i in ("--help") do set _CMP=%~i
>set _CMP=--help
>set _ARGS=""
>goto :EOF
>goto procArg
>if ["--help"] == [""] (
set _ARGS=
 goto argsDone
)
>REM NOTE: If you'd like to use a parameter withunderscore in its name,
>REM NOTE: use the quoted value: --do_stuff -> --do_Ustuff
>if ["--help"] == ["--"] goto argsDone
Files\Java\jdk1.6.0] was unexpected at this time.
>   if [C:\Program Files\Java\jdk1.6.0] == [] (
msg3639 (view) Author: Oti Humbel (otmarhumbel) Date: 2008-10-03.07:56:59
Many thanks!
I'll check this again as soon as I can get hands on a windows machine.
msg3672 (view) Author: Oti Humbel (otmarhumbel) Date: 2008-10-13.16:37:12
Finally I begin to understand the cause of the problem.
The cmd shell transscript below (Windows Vista, 32bit) shows that
jython.bat breaks if the environment variable JAVA_HOME is not quoted,
and works if JAVA_HOME is quoted:


C:\stuff\jython\jython-2.5a3\bin>set JAVA_HOME
JAVA_HOME=C:\Program Files\Java\jre1.6.0_07

C:\stuff\jython\jython-2.5a3\bin>jython.bat
"Files\Java\jre1.6.0_07]" kann syntaktisch an dieser Stelle nicht
verarbeitet werden.

C:\stuff\jython\jython-2.5a3\bin>set JAVA_HOME="C:\Program
Files\Java\jre1.6.0_07"

C:\stuff\jython\jython-2.5a3\bin>set JAVA_HOME
JAVA_HOME="C:\Program Files\Java\jre1.6.0_07"

C:\stuff\jython\jython-2.5a3\bin>jython.bat
Jython 2.5a3 (trunk:5315:5317, Sep 10 2008, 20:54:23)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_07
Type "help", "copyright", "credits" or "license" for more information.
>>> 


Since we cannot make assumptions how a user will define JAVA_HOME, I
have to find a way for empty-test JAVA_HOME both in the quoted and
unquoted case.
msg3682 (view) Author: Oti Humbel (otmarhumbel) Date: 2008-10-14.12:31:05
To illustrate the problem:

  C:\stuff\temp>set TEST=my test
  C:\stuff\temp>echo %TEST%
  my test
  C:\stuff\temp>if not [%TEST%]==[] echo [%TEST%] is set
  "test]==[]" is syntactically not valid here
  C:\stuff\temp>if not "%TEST%"=="" echo [%TEST%] is set
  [my test] is set
  C:\stuff\temp>if not '%TEST%'=='' echo [%TEST%] is set
  "test'==''" is syntactically not valid here

  C:\stuff\temp>set TEST="my test"
  C:\stuff\temp>echo %TEST%
  "my test"
  C:\stuff\temp>if not [%TEST%]==[] echo [%TEST%] is set
  ["my test"] is set
  C:\stuff\temp>if not "%TEST%"=="" echo [%TEST%] is set
  "test""==""" is syntactically not valid here
  C:\stuff\temp>if not '%TEST%'=='' echo [%TEST%] is set
  ["my test"] is set

The error message is my translation from the German:
  kann syntaktisch an dieser Stelle nicht verarbeitet werden

Summary:
There is no common syntax for testing the emptiness of a string
(containing spaces, quoted or unquoted).
msg3683 (view) Author: Oti Humbel (otmarhumbel) Date: 2008-10-14.12:39:36
The attached test_empty.bat allows quoted and unquoted strings to be
tested for emptiness.
The output is as follows:

  C:\stuff\temp>test_empty.bat

  ["my home 1"] was set: 1
  command: ["my home 1\bin\java"]

  [my home 2] was set: 1
  command: ["my home 2\bin\java"]

  [""] was set: 0
  command: [java]

  [] was set: 0
  command: [java]

  [] was set: 0
  command: [java]

  ["myhome6"] was set: 1
  command: ["myhome6\bin\java"]

  [myhome7] was set: 1
  command: ["myhome7\bin\java"]


  Legend: 1 = the variable is set,
          0 = it is not set


The key line is the for loop:
  for /f "useback tokens=*" %%a in ('%_TRIMMED_VAR%') do set
_TRIMMED_VAR=%%~a

, which should be applicable to jython.bat as well.
msg3686 (view) Author: Oti Humbel (otmarhumbel) Date: 2008-10-15.08:21:18
http://jython.svn.sourceforge.net/jython/?rev=5397&view=rev should fix this

The attached jython.bat.log shows the relevant lines of jython.bat for
different settings of JAVA_HOME (with echo on, and some lines cut for
better readability)
msg3687 (view) Author: Oti Humbel (otmarhumbel) Date: 2008-10-15.09:00:14
There is still a follow-up issue in the boot classpath calculation. 
If JYTHON_HOME is set unquoted to a directory containing a space, such as 
  JYTHON_HOME=C:\stuff\jython\bat test
, the java command looks like:

"C:\Program Files\Java\jre1.6.0_07\bin\java"  -Xss512k
-Xbootclasspath/a:C:\stuff\jython\bat
test\jython.jar;"C:\stuff\jython\bat" -Dpython.home=C:\stuff\jython\bat
test -Dpython.executable="C:\stuff\jython\bat test\bin\jython.bat"
-classpath ".;C:\Program Files\Java\jre1.6.0_07\lib\ext\QTJava.zip"
org.python.util.jython

which inevitably leads to:

Exception in thread "main" java.lang.NoClassDefFoundError:
test\jython/jar;C:\stuff\jython\bat
Caused by: java.lang.ClassNotFoundException:
test\jython.jar;C:\stuff\jython\bat
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
msg3754 (view) Author: Oti Humbel (otmarhumbel) Date: 2008-11-05.07:33:10
http://jython.svn.sourceforge.net/viewvc/jython?view=rev&revision=5544 is 
the groundwork for autotesting these problems
msg3755 (view) Author: Oti Humbel (otmarhumbel) Date: 2008-11-05.15:39:41
http://jython.svn.sourceforge.net/viewvc/jython?view=rev&revision=5545
and
http://jython.svn.sourceforge.net/viewvc/jython?view=rev&revision=5546
finally fix this issue.

The main part of the fix already is on beta 0, the last one (mentioned
in http://bugs.jython.org/msg3687) will be on the next beta.
History
Date User Action Args
2008-11-05 15:39:42otmarhumbelsetstatus: open -> closed
resolution: fixed
messages: + msg3755
2008-11-05 07:33:11otmarhumbelsetmessages: + msg3754
2008-10-15 09:00:15otmarhumbelsetmessages: + msg3687
2008-10-15 08:21:19otmarhumbelsetfiles: + jython.bat.log
messages: + msg3686
2008-10-14 12:39:36otmarhumbelsetfiles: + test_empty.bat
messages: + msg3683
2008-10-14 12:31:05otmarhumbelsetmessages: + msg3682
2008-10-13 16:37:12otmarhumbelsetmessages: + msg3672
2008-10-03 07:56:59otmarhumbelsetmessages: + msg3639
2008-09-26 17:57:12mr_tinessetmessages: + msg3624
2008-09-25 11:35:49otmarhumbelsetmessages: + msg3622
2008-09-24 17:17:52mr_tinessetnosy: + mr_tines
messages: + msg3621
2008-09-15 21:43:28otmarhumbelsetmessages: + msg3602
2008-09-13 17:32:01fwierzbickisetassignee: otmarhumbel
messages: + msg3511
nosy: + fwierzbicki, otmarhumbel
2008-09-10 16:04:57foripperzsettitle: [bug]not valid JAVA_HOME path -> not valid JAVA_HOME path
2008-09-10 16:04:29foripperzcreate