gridgain / gridgain-old

268 stars 85 forks source link

Exception thrown when starting GridGain on UNC path in windows #15

Closed echu79 closed 10 years ago

echu79 commented 10 years ago

In GridUtils.resolveProjectHome() it throws the following exception when the jar/class files are located on a UNC path in Windows:

Exception in thread "main" java.lang.IllegalArgumentException: URI has an authority component
    at java.io.File.<init>(File.java:397)
    at org.gridgain.grid.util.GridUtils.resolveProjectHome(GridUtils.java:2476)
    at org.gridgain.grid.util.GridUtils.getGridGainHome(GridUtils.java:2519)
    at org.gridgain.grid.GridGain$GridNamedInstance.start0(GridGain.java:1326)
    at org.gridgain.grid.GridGain$GridNamedInstance.start(GridGain.java:1291)
    at org.gridgain.grid.GridGain.start0(GridGain.java:850)
    at org.gridgain.grid.GridGain.start(GridGain.java:780)
    at org.gridgain.grid.GridGain.start(GridGain.java:709)
    at org.gridgain.grid.GridGain.start(GridGain.java:550)

This seems to be a long standing issue with Java and UNC paths on windows. If you are only supported Java 7+, it can be fixed by changing the following around line 2476 in GridUtils.java

for (File cur = new File(uri).getAbsoluteFile(); cur != null; cur = cur.getParentFile()) {

to

for (File cur = Paths.get(uri).toFile().getAbsoluteFile(); cur != null; cur = cur.getParentFile()) {

If supporting < Java 7, there are a number of workarounds floating around the net. http://wiki.eclipse.org/Eclipse/UNC_Paths http://www.tomergabel.com/JavaMishandlesUNCPathsOnWindows.aspx

Thanks!

dsetrakyan commented 10 years ago

Internal ticket has been filed. It will be fixed in the next release.

devozerov commented 10 years ago

I'm not sure if proposed fix is the way to go. Normaly path to JAR in local file system is resolved as "file:/c:/path/to/jar" and is handled correctly: new File(new URI("file:/c:/path/to/jar")) will not throw an exception. However, if the path for some reason has two slashes, e.g. "file://c:/path/to/jar" mentioned exception is thrown. The problem, is that passing this string to Paths.get(uri).toFile() will not throw an exception, but will resolve the path incorrectly, returning "\c\path\to\jar" which cannot be resolved to a file. So it looks like the only way we can deal with this issue is to follow the blog post you mentioned (http://www.tomergabel.com/JavaMishandlesUNCPathsOnWindows.aspx).

devozerov commented 10 years ago

The issue is resolved. See commit https://github.com/gridgain/gridgain/commit/b5e814b9f69faa2521e86fb3da82f28fb1b3d23c