Bug 56895

Summary: catalina.bat does not properly compose JAVA_OPTS
Product: Tomcat 7 Reporter: Lucas Theisen <lucastheisen>
Component: IntegrationAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 7.0.54   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description Lucas Theisen 2014-08-27 22:43:50 UTC
When composing JAVA_OPTS, the current bat script uses this approach:

set JAVA_OPTS=%JAVA_OPTS% %OTHER_STUFF%

However, this leads to issues if the existing JAVA_OPTS had some sort of escape sequence in it.  For example, in my setenv.bat, I add some proxy info:

SET "JAVA_OPTS=-Dhttp.proxyHost=myproxy.localdomain -Dhttp.nonProxyHosts=*.localdomain^|localhost^|appserver.localdomain"

Using the existing approach, the escape sequence ^| gets processed into | leaving the next evaluation to treat it as a command pipe, which causes immediate failure.

If instead you use this approach:

set "JAVA_OPTS=%JAVA_OPTS% %OTHER_STUFF%"

Then those escape sequences are preserved.  Here is the patch for version 7.0.54:

--- catalina.bat_ORIGINAL       2014-08-27 18:37:05.173641700 -0400
+++ catalina.bat        2014-08-27 18:06:22.779721000 -0400
@@ -176,12 +176,12 @@
 if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliConfig
 set LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
 :noJuliConfig
-set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%
+set "JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%"

 if not "%LOGGING_MANAGER%" == "" goto noJuliManager
 set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
 :noJuliManager
-set JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%
+set "JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%"

 rem ----- Execute The Requested Command ---------------------------------------
Comment 1 Mark Thomas 2014-09-03 14:11:08 UTC
Fixed in 8.0.x for 8.0.12 onwards and in 7.0.x for 7.0.56 onwards.
Comment 2 Ognjen Blagojevic 2014-10-03 07:15:01 UTC
(In reply to Mark Thomas from comment #1)
> Fixed in 8.0.x for 8.0.12 onwards and in 7.0.x for 7.0.56 onwards.

FTR, 8.0.12 was already released at the moment the patch is applied. 8.0.13 iz skipped, therefore, it is 8.0.14 onwards.

-Ognjen