Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPF fails with java.lang.IllegalArgumentException: Null charset name #429

Open
aoli-al opened this issue Dec 21, 2023 · 3 comments
Open

Comments

@aoli-al
Copy link
Contributor

aoli-al commented Dec 21, 2023

Hi, I'm trying to use JPF to run the following simple program

import java.nio.file.Path;
public class BoundedBuffer {
  public static void main(String [] args) {
    Path.of("/tmp");
  }
}

I got the following exception:

JavaPathfinder core system v8.0 (rev 1a704e1d6c3d92178504f8cdfe57b068b4e22d9c) - (C) 2005-2014 United States Government. All rights reserved.


====================================================== system under test
BoundedBuffer.main()

====================================================== search started: 12/21/23, 3:01 PM
[WARNING] orphan NativePeer method: jdk.internal.misc.Unsafe.getUnsafe()Lsun/misc/Unsafe;

====================================================== error 1
gov.nasa.jpf.vm.NoUncaughtExceptionsProperty
java.lang.IllegalArgumentException: Null charset name
	at java.nio.charset.Charset.lookup(Charset.java:455)
	at java.nio.charset.Charset.forName(Charset.java:526)
	at sun.nio.fs.Util.<clinit>(Util.java:40)
	at sun.nio.fs.UnixFileSystem.<init>(UnixFileSystem.java:51)
	at sun.nio.fs.LinuxFileSystem.<init>(LinuxFileSystem.java:39)
	at sun.nio.fs.LinuxFileSystemProvider.newFileSystem(LinuxFileSystemProvider.java:46)
	at sun.nio.fs.LinuxFileSystemProvider.newFileSystem(LinuxFileSystemProvider.java:39)
	at sun.nio.fs.UnixFileSystemProvider.<init>(UnixFileSystemProvider.java:56)
	at sun.nio.fs.LinuxFileSystemProvider.<init>(LinuxFileSystemProvider.java:41)
	at sun.nio.fs.DefaultFileSystemProvider.<clinit>(DefaultFileSystemProvider.java:35)
	at java.nio.file.FileSystems.getDefault(FileSystems.java:185)
	at java.nio.file.Path.of(Path.java:147)
	at BoundedBuffer.main(BoundedBuffer.java:121)


====================================================== snapshot #1
thread java.lang.Thread:{id:0,name:main,status:RUNNING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  owned locks:java.lang.Class@20b,java.lang.Class@278
  call stack:
	at sun.nio.fs.Util.<clinit>(Util.java:40)
	at sun.nio.fs.UnixFileSystem.<init>(UnixFileSystem.java:51)
	at sun.nio.fs.LinuxFileSystem.<init>(LinuxFileSystem.java:39)
	at sun.nio.fs.LinuxFileSystemProvider.newFileSystem(LinuxFileSystemProvider.java:46)
	at sun.nio.fs.LinuxFileSystemProvider.newFileSystem(LinuxFileSystemProvider.java:39)
	at sun.nio.fs.UnixFileSystemProvider.<init>(UnixFileSystemProvider.java:56)
	at sun.nio.fs.LinuxFileSystemProvider.<init>(LinuxFileSystemProvider.java:41)
	at sun.nio.fs.DefaultFileSystemProvider.<clinit>(DefaultFileSystemProvider.java:35)
	at java.nio.file.FileSystems.getDefault(FileSystems.java:185)
	at java.nio.file.Path.of(Path.java:147)
	at BoundedBuffer.main(BoundedBuffer.java:121)


====================================================== results
error #1: gov.nasa.jpf.vm.NoUncaughtExceptionsProperty "java.lang.IllegalArgumentException: Null charset n..."

====================================================== statistics
elapsed time:       00:00:00
states:             new=1,visited=0,backtracked=0,end=0
search:             maxDepth=1,constraints=0
choice generators:  thread=1 (signal=0,lock=1,sharedRef=0,threadApi=0,reschedule=0), data=0
heap:               new=691,released=0,maxLive=0,gcCycles=0
instructions:       11128
max memory:         500MB
loaded code:        classes=114,methods=2364

====================================================== search finished: 12/21/23, 3:01 PM

Could you please help me to fix this issue?

@cyrille-artho
Copy link
Member

This exception happens because an internal default setting is set or initialized by the Java library, but not by the libraries that JPF uses. This can be because an existing model class (such as the classes in `src/classes/modules/java.base/java/nio) does not set a certain field. However, without further investigation, it is difficult to tell what the root cause is.
In any case, thanks to your report, we have a reproducible test for this.

Ideally, we can fix this by changing an existing class (in the model classes or a native peer class). If there is no way to fix it there, a new model class (in package java.nio.charset or java.nio.file) can fix the problem, at the expense of having an additional model class to maintain.

@adysinghh
Copy link

@cyrille-artho Hi, Can I fix this issue ?

@cyrille-artho
Copy link
Member

Yes, please give it a try.

joalen added a commit to joalen/jpf-core that referenced this issue Nov 17, 2024
Seems like there needs to be model classes in the file and charset packages for java.nio. These are as small as I could make them
joalen added a commit to joalen/jpf-core that referenced this issue Nov 17, 2024
Developed UnitTest to address the error from javapathfinder#429
cyrille-artho pushed a commit that referenced this issue Dec 15, 2024
 (#506)

* Found Potential Fix for #429

Seems like there needs to be model classes in the file and charset packages for java.nio. These are as small as I could make them

* Create NullCharsetTest.java

Developed UnitTest to address the error from #429

* Update NullCharsetTest.java

Should be "iae" and not "e"

* Fixed Failing Tests for NullCharSet

It turns out my implementation of Charset affected the behavior of underlying Gradle JPF tests. Removed this custom Charset implementation and instead kept four files to fix the root cause:
 - FileSystem.java
 - FileSystems.java
 - Pathy.java
 - spi/FileSystemProvider.java

All other files in the initial commit to PR were redundant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants