question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.IllegalArgumentException when running demo

See original GitHub issue

Version : 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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mordechaimcommented, Oct 22, 2020

Thanks for your thorough report.

Perhaps I shouldn’t rely on relativize() but instead use string manipulation to avoid this inconsistency.

0reactions
Gu-Licommented, Oct 22, 2020

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).

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

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.IllegalArgumentException during testing #82 - GitHub
I have a Spring Boot project that I want to check for Dependency cycles with Degraph. I use the following Dependendencies for that:...
Read more >
How to solve an IllegalArgumentException in Java?
An IllegalArgumentException is thrown in order to indicate that a method has been passed an illegal argument. This exception extends the ...
Read more >
getting this error in springboot application java.lang ...
IllegalArgumentException: Not a managed type - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational ...
Read more >
[Solved] java.lang.IllegalArgumentException in Java
This exception extends Runtime Exception and thus can be thrown during the operation of Java Virtual Machine (JVM). Due to this reason, it...
Read more >
cucumber java.lang.IllegalArgumentException: Not a file or ...
Just create a new feature file , copy all the scenarios from the first feature file and paste it in the new one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found