Skip to content

Commit

Permalink
I have made the suggested changes.
Browse files Browse the repository at this point in the history
When I am rebuilding, the exception is caught and the test fails with the message.
  • Loading branch information
sanidhya00081 committed Jan 15, 2025
1 parent d5a7bf8 commit 04b5b9d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions __test__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
***
Empty file added _test_
Empty file.
Binary file added lib/junit-4.13.2.jar
Binary file not shown.
8 changes: 8 additions & 0 deletions src/main/gov/nasa/jpf/D.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gov.nasa.jpf;

public class D {
// Non-static method
public void m() {
System.out.println("Non-static method executed.");
}
}
18 changes: 5 additions & 13 deletions src/tests/gov/nasa/jpf/StaticCallToNonStaticTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,15 @@

public class StaticCallToNonStaticTest extends TestJPF {

// A non-static method
public void nonStaticMethod() {
System.out.println("Non-static method executed.");
}

// Test case to verify JPF behavior
@Test
public void testStaticCallToNonStatic() {
// Using JPF’s verification mechanism
if (verifyNoPropertyViolation()) {
// Simulating a static method call to a non-static method
StaticCallToNonStaticTest instance = null;
try {
instance.nonStaticMethod(); // This should fail because it's a static call to a non-static method
} catch (NullPointerException e) {
// Expected exception: this will be caught as instance is null
System.out.println("Caught expected NullPointerException: " + e.getMessage());
// Attempting to call non-static method m() on class D without an instance
D.m(); // This should throw IncompatibleClassChangeError after D.java is recompiled without static
} catch (IncompatibleClassChangeError e) {
// Expected exception: this is the behavior we want to test
System.out.println("Caught expected IncompatibleClassChangeError: " + e.getMessage());
}
}
}
Expand Down

0 comments on commit 04b5b9d

Please sign in to comment.