java.lang.IllegalArgumentException when running demo
See original GitHub issueVersion : update4j@1.5.5 Platform: mac OS 10.15.7 / windows 10
When I ran the demo, I got the same problem as issue#113
Exception in thread "main" java.lang.IllegalArgumentException
at jdk.zipfs/jdk.nio.zipfs.ZipPath.relativize(ZipPath.java:230)
at org.update4j.Archive.lambda$load$1(Archive.java:80)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
at org.update4j.Archive.load(Archive.java:92)
at org.update4j.Archive.read(Archive.java:40)
at org.update4j.service.DefaultBootstrap.updateFirst(DefaultBootstrap.java:211)
at org.update4j.service.DefaultBootstrap.main(DefaultBootstrap.java:147)
at org.update4j.Bootstrap.start(Bootstrap.java:297)
at org.update4j.Bootstrap.start(Bootstrap.java:280)
at org.update4j.Bootstrap.start(Bootstrap.java:182)
at org.update4j.Bootstrap.main(Bootstrap.java:113)
I tried to run with different versions of JDK (v11.0.8、v11.0.9、v9.0.4 from oracle official website) on mac os and windows, but it still didn’t get better.
But when I replaced JDK with adoptopenjdk 11.0.8 (from here), the demo ran successfully.
I checked the code and guessed that the problem may come from
org.update4j.Archive.java:78
try (Stream<Path> stream = Files.walk(filesPath)) {
...
So I executed the same test code with two versions of JDK, and got different results: test code
public static void main(String[] args) throws IOException {
Path zip = Paths.get( "update.zip");
System.out.println(zip.toAbsolutePath());
FileSystem fileSystem = FileSystems.newFileSystem(zip, (ClassLoader) null);
Path filesPath = fileSystem.getPath("files");
Stream<Path> stream = Files.walk(filesPath);
stream.forEach(p -> System.out.println(p.toString()+"=======> isAbsolute: "+ p.isAbsolute() ));
}
run with oracle JDK v11.0.9
Connected to the target VM, address: '127.0.0.1:63760', transport: 'socket'
/Users/a175/IdeaProjects/demo/update4j/demo-master/update.zip
files=======> isAbsolute: false
/files/Users=======> isAbsolute: true
/files/Users/a175=======> isAbsolute: true
/files/Users/a175/IdeaProjects=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo/update4j=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo/update4j/test=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap/javafx-graphics-11.0.1-mac.jar=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap/javafx-fxml-11.0.1-mac.jar=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap/javafx-controls-11.0.1-mac.jar=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap/javafx-base-11.0.1-mac.jar=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap/bootstrap-1.0.0.jar=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo/update4j/test/business=======> isAbsolute: true
/files/Users/a175/IdeaProjects/demo/update4j/test/business/config.xml=======> isAbsolute: true
Disconnected from the target VM, address: '127.0.0.1:63760', transport: 'socket'
Process finished with exit code 0
$ java -version
java version "11.0.9" 2020-10-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)
run with adoptopenjdk 11.0.8
Connected to the target VM, address: '127.0.0.1:51528', transport: 'socket'
/Users/a175/IdeaProjects/demo/update4j/demo-master/update.zip
files=======> isAbsolute: false
files/Users=======> isAbsolute: false
files/Users/a175=======> isAbsolute: false
files/Users/a175/IdeaProjects=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo/update4j=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo/update4j/test=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap/javafx-graphics-11.0.1-mac.jar=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap/javafx-fxml-11.0.1-mac.jar=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap/javafx-controls-11.0.1-mac.jar=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap/javafx-base-11.0.1-mac.jar=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo/update4j/test/bootstrap/bootstrap-1.0.0.jar=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo/update4j/test/business=======> isAbsolute: false
files/Users/a175/IdeaProjects/demo/update4j/test/business/config.xml=======> isAbsolute: false
Disconnected from the target VM, address: '127.0.0.1:51528', transport: 'socket'
Process finished with exit code 0
$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)
The results show that there are differences in the path prefixes obtained by Files.walk()
of different versions of JDK when traversing files, one has “/” while the other does not.
This may cause the program to throw IllegalArgumentException
when it reaches the filesPath.relativize(p)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Thanks for your thorough report.
Perhaps I shouldn’t rely on
relativize()
but instead use string manipulation to avoid this inconsistency.Sorry for the late reply. I just tested Oracle JDK 15.0.1 and OpenJDK 15 with the same test code, and the execution results of the
Files.walk()
method of the two versions of jdk are the same. Like OpenJDK 11, they all output relative paths when traversing directories (without the “/” prefix).Then I tested the update4j@1.5.5 demo with Oracle JDK 15, and it ran successfully. So as you guessed, Oracle JDK 15 should have fixed this problem.