Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file.separator Java 7 option causes ExceptionInInitializerError

We have a TeamCity (7.0.3) agent running on a 64-bit Windows Server 2008 machine. When we recently upgraded the agent to use Java 7 (1.7.0_10) the builds started failing with the following stacktrace:

Error occurred during initialization of VM
java.lang.ExceptionInInitializerError
    at java.lang.Runtime.loadLibrary0(Runtime.java:841)
    at java.lang.System.loadLibrary(System.java:1084)
    at java.lang.System.initializeSystemClass(System.java:1145)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(String.java:658)
    at java.io.Win32FileSystem.<init>(Win32FileSystem.java:40)
    at java.io.WinNTFileSystem.<init>(WinNTFileSystem.java:37)
    at java.io.FileSystem.getFileSystem(Native Method)
    at java.io.File.<clinit>(File.java:156)
    at java.lang.Runtime.loadLibrary0(Runtime.java:841)
    at java.lang.System.loadLibrary(System.java:1084)
    at java.lang.System.initializeSystemClass(System.java:1145)

The problem seems to be caused by the inclusion of the "-Dfile.separator=\" java option that TeamCity uses in the executable command for the agent. I was able to reproduce the problem by writing a simple "Hello World" class and compiling it on the Windows box and then running the program with the file.separator option (i.e. java -Dfile.separator=\ HelloWorld)

I haven't found any similar bug reports. Has anyone seen anything like this? Has the behaviour of file.separator changed in Java 7?

Furthermore I realise that \ is the default file.separator for Windows anyway so I don't think the agent really needs to use it in the executable command, however I can't see a way in TeamCity to tell the agent not to include it. Is it possible to do this?

like image 779
GaZ Avatar asked Dec 17 '12 11:12

GaZ


2 Answers

Try the JVM command line parameter -Dfile.separator=\/ (i.e., specify both a backward and forward slash).

like image 59
Michael Avatar answered Oct 22 '22 20:10

Michael


It looks java.exe now trims trailing \ (back-slash).

I have the following code: import java.lang.*;

public class test {
  public static void main(String[] argz) { 
    for(String s : argz) {
     System.out.println("agg=" + s + "|");
    }

    System.out.println("prop=" +  System.getProperty("prop") + "|");
  }
}

I start it with Java 1.7.0_07 and _10:

C:\Java\jdk1.7.0_07\bin\java.exe -cp . -Dprop=z\\ test a\\ b
agg=a\\|
agg=b|
prop=z\\|

and _10

C:\Java\jdk1.7.0_10\bin\java.exe -cp . -Dprop=z\\ test a\\ b
agg=a|
agg=b|
prop=z|

And one more series:

C:\Java\jdk1.7.0_07\bin\java.exe -cp . -Dprop=z\ test a\ b
agg=a\|
agg=b|
prop=z\|

and _10

C:\Java\jdk1.7.0_10\bin\java.exe -cp . -Dprop=z\ test a\ b
agg=a|
agg=b|
prop=z|
like image 24
Eugene Petrenko Avatar answered Oct 22 '22 20:10

Eugene Petrenko