Skip to content

Current issue with jpf nas #4

@Mahmoud-Khawaja

Description

@Mahmoud-Khawaja

There was a classpath issue with jpf-nas, referring to #1 in jpf.properties.

1. Classpath Problem
Issue: TestNasJPF.class is located at:

build/classes/java/main/nas/util/test/TestNasJPF.class

But the original jpf.properties only included:

jpf-nas.classpath = \
   ${jpf-nas}/build/libs/jpf-nas-classes.jar;\
   ${jpf-nas}/build/classes/java/test

Missing directories:

build/classes/java/main
build/classes/java/examples

Before the fix, 3 tests appeared to "pass" but were actually never executed. JPF tests use this pattern:

I looked at the tests and I found that the structure looks like:

if (mpVerifyNoPropertyViolation(2, args)) {
    // Test body here
}

What was happening:

  • When the if condition returned false:
  • The test body was skipped entirely
  • JUnit saw the method complete without assertions failing
  • Result: "PASSED" (it's tricky because it's never executed)

The two failed tests failed because they probably were hitting the classpath error during JPF setup before the if condition could return false, causing actual test failures.

After the fix:

  • All JPF framework calls succeed in starting JPF
  • All if conditions return true
  • All test bodies actually execute
  • But they all hit the Java 11 SharedSecrets issue when JPF tries to create ServerSocket objects

2. Java 11 SharedSecrets Issue

The problem is all the tests failed.

After checking the log I found this:

java.lang.NoSuchMethodException: jdk.internal.misc.SharedSecrets.setJavaNetSocketAccess(Ljdk/internal/misc/JavaNetSocketAccess;)V
at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)

This means Java 11 changed the internal networking APIs that JPF-NAS relied on. When ServerSocket tries to initialize, it calls SharedSecrets.setJavaNetSocketAccess().

So, the issue is related to the Java version.

After analyzing the issue I found out that we need to create something to provide access to Java networking implementation for SharedSecrets.

package jdk.internal.misc;

import java.net.SocketImpl;
import java.net.ServerSocket;

public interface JavaNetSocketAccess {
    SocketImpl newSocketImpl(Class<? extends SocketImpl> clazz);
    ServerSocket newServerSocket(SocketImpl impl);  // Returns ServerSocket, not SocketImpl!
}

Purpose: This enables JPF's Network Interception Architecture:

Java 11 Application Code
         |
   JDK Internal APIs (java.net.*)
         |
   SharedSecrets.getJavaNetSocketAccess()
         |
   JPF's JavaNetSocketAccess Implementation  ← **THIS INTERFACE**
        |
   JPF Model Classes (ServerSocket, Socket, etc.)

Without this interface: JPF cannot intercept networking operations, making network verification impossible.

in SharedSecrets.java we added

private static JavaNetSocketAccess javaNetSocketAccess;

public static void setJavaNetSocketAccess(JavaNetSocketAccess jnsa) {
    javaNetSocketAccess = jnsa;
}

public static JavaNetSocketAccess getJavaNetSocketAccess() {
    if (javaNetSocketAccess == null)
        unsafe.ensureClassInitialized(java.net.ServerSocket.class);
    return javaNetSocketAccess;
}

back to jpf nas i added this static block in ServerSocket.java

static {
    try {
        jdk.internal.misc.SharedSecrets.setJavaNetSocketAccess(
            new jdk.internal.misc.JavaNetSocketAccess() {
                @Override
                public SocketImpl newSocketImpl(Class<? extends SocketImpl> clazz) {
                    return new SocketImpl();
                }

                @Override
                public ServerSocket newServerSocket(SocketImpl impl) {
                    return null;
                }
            }
        );
    } catch (Exception e) {
        // Exception ignored for graceful degradation
    }
}

It will execute immediately when JPF-NAS ServerSocket model class loads and must happen before Java's built-in ServerSocket initializes.

JPF Model Class Integration Architecture

Java 11 Application
         |
   Uses ServerSocket/Socket
         |
   JDK Internal Code calls SharedSecrets.getJavaNetSocketAccess()
         |
   Returns OUR implementation (registered by this static block)  
         |
   Calls our newSocketImpl()/newServerSocket() methods
         |
   Returns JPF model objects for verification

now if we tried to run the tests again we get in the output

running jpf with args: +search.multiple_errors = true +vm.process_finalizers = true +vm.nas.initiating_target = 0
JavaPathfinder core system v8.0 (rev 70c3013c60d627bc8158316abcf82fe503f5ae15) - (C) 2005-2014 United States Government. All rights reserved.

whick means that jpf runs successfully

the problem is we still have this error presist

java.lang.NoSuchMethodException: jdk.internal.misc.SharedSecrets.setJavaNetSocketAccess(...)
at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)

this is teh log i have

running jpf with args: +search.multiple_errors = true +vm.process_finalizers = true +vm.nas.initiating_target = 0
JavaPathfinder core system v8.0 (rev 70c3013c60d627bc8158316abcf82fe503f5ae15) - (C) 2005-2014 United States Government. All rights reserved.


====================================================== system under test
net.nas.SocketTest.runTestMethod()

====================================================== search started: 6/30/25, 5:47 AM
[WARNING] orphan NativePeer method: java.net.ServerSocket.CheckForAddressAlreadyInUse(I)V
[WARNING] orphan NativePeer method: java.net.ServerSocket.accept0()Ljava/net/Socket;

====================================================== error 1
gov.nasa.jpf.vm.NoUncaughtExceptionsProperty
java.lang.NoSuchMethodException: jdk.internal.misc.SharedSecrets.setJavaNetSocketAccess(Ljdk/internal/misc/JavaNetSocketAccess;)V
	at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)
	at net.nas.SocketTest.testTimedoutAccept(SocketTest.java:65)
	at java.lang.reflect.Method.invoke(gov.nasa.jpf.vm.JPF_java_lang_reflect_Method)
	at gov.nasa.jpf.util.test.TestJPF.runTestMethod(TestJPF.java:648)


====================================================== 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@230
  call stack:
	at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)
	at net.nas.SocketTest.testTimedoutAccept(SocketTest.java:65)
	at java.lang.reflect.Method.invoke(Method.java)
	at gov.nasa.jpf.util.test.TestJPF.runTestMethod(TestJPF.java:648)

thread gov.nasa.jpf.FinalizerThread:{id:1,name:finalizer,status:WAITING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  waiting on: java.lang.Object@d6
  call stack:


====================================================== thread ops #1
   1     trans      insn          loc                : stmt
------- ---------------------------------------------------
W:d6         0      invokevirtual gov/nasa/jpf/FinalizerThread.java:0

====================================================== results
error #1: gov.nasa.jpf.vm.NoUncaughtExceptionsProperty "java.lang.NoSuchMethodException: jdk.internal.misc..."

====================================================== search finished: 6/30/25, 5:47 AM
  running jpf with args: +search.multiple_errors = true +vm.process_finalizers = true +vm.nas.initiating_target = 0
JavaPathfinder core system v8.0 (rev 70c3013c60d627bc8158316abcf82fe503f5ae15) - (C) 2005-2014 United States Government. All rights reserved.


====================================================== system under test
net.nas.SocketTest.runTestMethod()+net.nas.SocketTest.runTestMethod()

====================================================== search started: 6/30/25, 5:47 AM
[WARNING] orphan NativePeer method: java.net.ServerSocket.CheckForAddressAlreadyInUse(I)V
[WARNING] orphan NativePeer method: java.net.ServerSocket.accept0()Ljava/net/Socket;

====================================================== error 1
gov.nasa.jpf.vm.NoUncaughtExceptionsProperty
java.lang.NoSuchMethodException: jdk.internal.misc.SharedSecrets.setJavaNetSocketAccess(Ljdk/internal/misc/JavaNetSocketAccess;)V
	at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)
	at net.nas.SocketTest.testTimedoutRead(SocketTest.java:121)
	at java.lang.reflect.Method.invoke(gov.nasa.jpf.vm.JPF_java_lang_reflect_Method)
	at gov.nasa.jpf.util.test.TestJPF.runTestMethod(TestJPF.java:648)


====================================================== 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@304
  call stack:
	at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)
	at net.nas.SocketTest.testTimedoutRead(SocketTest.java:121)
	at java.lang.reflect.Method.invoke(Method.java)
	at gov.nasa.jpf.util.test.TestJPF.runTestMethod(TestJPF.java:648)

thread gov.nasa.jpf.FinalizerThread:{id:2,name:finalizer,status:WAITING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  waiting on: java.lang.Object@d6
  call stack:

thread java.lang.Thread:{id:1,name:main,status:RUNNING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  call stack:

thread gov.nasa.jpf.FinalizerThread:{id:3,name:finalizer,status:WAITING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  waiting on: java.lang.Object@1ac
  call stack:


====================================================== thread ops #1
   3       2     trans      insn          loc                : stmt
------- ------- ---------------------------------------------------
W:1ac      |         0      invokevirtual gov/nasa/jpf/FinalizerThread.java:0
   |    W:d6         0      invokevirtual gov/nasa/jpf/FinalizerThread.java:0

====================================================== results
error #1: gov.nasa.jpf.vm.NoUncaughtExceptionsProperty "java.lang.NoSuchMethodException: jdk.internal.misc..."

====================================================== search finished: 6/30/25, 5:47 AM
  running jpf with args: +search.multiple_errors = true +vm.process_finalizers = true +vm.nas.initiating_target = 0
JavaPathfinder core system v8.0 (rev 70c3013c60d627bc8158316abcf82fe503f5ae15) - (C) 2005-2014 United States Government. All rights reserved.


====================================================== system under test
net.nas.SocketTest.runTestMethod()+net.nas.SocketTest.runTestMethod()

====================================================== search started: 6/30/25, 5:47 AM
[WARNING] orphan NativePeer method: java.net.ServerSocket.CheckForAddressAlreadyInUse(I)V
[WARNING] orphan NativePeer method: java.net.ServerSocket.accept0()Ljava/net/Socket;

====================================================== error 1
gov.nasa.jpf.vm.NoUncaughtExceptionsProperty
java.lang.NoSuchMethodException: jdk.internal.misc.SharedSecrets.setJavaNetSocketAccess(Ljdk/internal/misc/JavaNetSocketAccess;)V
	at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)
	at net.nas.SocketTest.testHash(SocketTest.java:83)
	at java.lang.reflect.Method.invoke(gov.nasa.jpf.vm.JPF_java_lang_reflect_Method)
	at gov.nasa.jpf.util.test.TestJPF.runTestMethod(TestJPF.java:648)


====================================================== 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@304
  call stack:
	at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)
	at net.nas.SocketTest.testHash(SocketTest.java:83)
	at java.lang.reflect.Method.invoke(Method.java)
	at gov.nasa.jpf.util.test.TestJPF.runTestMethod(TestJPF.java:648)

thread gov.nasa.jpf.FinalizerThread:{id:2,name:finalizer,status:WAITING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  waiting on: java.lang.Object@d6
  call stack:

thread java.lang.Thread:{id:1,name:main,status:RUNNING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  call stack:

thread gov.nasa.jpf.FinalizerThread:{id:3,name:finalizer,status:WAITING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  waiting on: java.lang.Object@1ac
  call stack:


====================================================== thread ops #1
   3       2     trans      insn          loc                : stmt
------- ------- ---------------------------------------------------
W:1ac      |         0      invokevirtual gov/nasa/jpf/FinalizerThread.java:0
   |    W:d6         0      invokevirtual gov/nasa/jpf/FinalizerThread.java:0

====================================================== results
error #1: gov.nasa.jpf.vm.NoUncaughtExceptionsProperty "java.lang.NoSuchMethodException: jdk.internal.misc..."

====================================================== search finished: 6/30/25, 5:47 AM
  running jpf with args: +search.multiple_errors = true +vm.process_finalizers = true +vm.nas.initiating_target = 0
JavaPathfinder core system v8.0 (rev 70c3013c60d627bc8158316abcf82fe503f5ae15) - (C) 2005-2014 United States Government. All rights reserved.


====================================================== system under test
net.nas.SocketTest.runTestMethod()+net.nas.SocketTest.runTestMethod()

====================================================== search started: 6/30/25, 5:47 AM
[WARNING] orphan NativePeer method: java.net.ServerSocket.CheckForAddressAlreadyInUse(I)V
[WARNING] orphan NativePeer method: java.net.ServerSocket.accept0()Ljava/net/Socket;

====================================================== error 1
gov.nasa.jpf.vm.NoUncaughtExceptionsProperty
java.lang.NoSuchMethodException: jdk.internal.misc.SharedSecrets.setJavaNetSocketAccess(Ljdk/internal/misc/JavaNetSocketAccess;)V
	at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)
	at net.nas.SocketTest.testEstablishingConnection(SocketTest.java:34)
	at java.lang.reflect.Method.invoke(gov.nasa.jpf.vm.JPF_java_lang_reflect_Method)
	at gov.nasa.jpf.util.test.TestJPF.runTestMethod(TestJPF.java:648)


====================================================== 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@304
  call stack:
	at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)
	at net.nas.SocketTest.testEstablishingConnection(SocketTest.java:34)
	at java.lang.reflect.Method.invoke(Method.java)
	at gov.nasa.jpf.util.test.TestJPF.runTestMethod(TestJPF.java:648)

thread gov.nasa.jpf.FinalizerThread:{id:2,name:finalizer,status:WAITING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  waiting on: java.lang.Object@d6
  call stack:

thread java.lang.Thread:{id:1,name:main,status:RUNNING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  call stack:

thread gov.nasa.jpf.FinalizerThread:{id:3,name:finalizer,status:WAITING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  waiting on: java.lang.Object@1ac
  call stack:


====================================================== thread ops #1
   3       2     trans      insn          loc                : stmt
------- ------- ---------------------------------------------------
W:1ac      |         0      invokevirtual gov/nasa/jpf/FinalizerThread.java:0
   |    W:d6         0      invokevirtual gov/nasa/jpf/FinalizerThread.java:0

====================================================== results
error #1: gov.nasa.jpf.vm.NoUncaughtExceptionsProperty "java.lang.NoSuchMethodException: jdk.internal.misc..."

====================================================== search finished: 6/30/25, 5:47 AM
  running jpf with args: +vm.process_finalizers=true
JavaPathfinder core system v8.0 (rev 70c3013c60d627bc8158316abcf82fe503f5ae15) - (C) 2005-2014 United States Government. All rights reserved.


====================================================== system under test
net.nas.SocketTest.runTestMethod()

====================================================== search started: 6/30/25, 5:47 AM
[WARNING] orphan NativePeer method: java.net.Socket.connect(Ljava/lang/String;I)V
[WARNING] orphan NativePeer method: java.net.ServerSocket.CheckForAddressAlreadyInUse(I)V
[WARNING] orphan NativePeer method: java.net.ServerSocket.accept0()Ljava/net/Socket;
I am here!!!

====================================================== error 1
gov.nasa.jpf.vm.NoUncaughtExceptionsProperty
java.lang.NoSuchMethodException: jdk.internal.misc.SharedSecrets.setJavaNetSocketAccess(Ljdk/internal/misc/JavaNetSocketAccess;)V
	at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)
	at net.nas.SocketTest$FinalizeServer.finalize(SocketTest.java:156)
	at gov.nasa.jpf.FinalizerThread.runFinalizer(gov.nasa.jpf.vm.JPF_gov_nasa_jpf_FinalizerThread)
	at gov.nasa.jpf.FinalizerThread.runAllFinalizers(FinalizerThread.java:44)
	at gov.nasa.jpf.FinalizerThread.processFinalizers(FinalizerThread.java:61)
	at gov.nasa.jpf.FinalizerThread.run(FinalizerThread.java:68)


====================================================== snapshot #1
thread gov.nasa.jpf.FinalizerThread:{id:1,name:finalizer,status:RUNNING,priority:5,isDaemon:false,lockCount:0,suspendCount:0}
  owned locks:java.lang.Class@239
  call stack:
	at java.net.ServerSocket.<clinit>(ServerSocket.java:1036)
	at net.nas.SocketTest$FinalizeServer.finalize(SocketTest.java:156)
	at gov.nasa.jpf.FinalizerThread.runFinalizer(FinalizerThread.java)
	at gov.nasa.jpf.FinalizerThread.runAllFinalizers(FinalizerThread.java:44)
	at gov.nasa.jpf.FinalizerThread.processFinalizers(FinalizerThread.java:61)
	at gov.nasa.jpf.FinalizerThread.run(FinalizerThread.java:68)


====================================================== thread ops #1
 trans      insn          loc                : stmt
---------------------------------------------------

====================================================== results
error #1: gov.nasa.jpf.vm.NoUncaughtExceptionsProperty "java.lang.NoSuchMethodException: jdk.internal.misc..."

====================================================== search finished: 6/30/25, 5:47 AM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions