Skip to content

Commit

Permalink
Fix incorrect IncompatibleClassChangeError in ClassInfo.getDefaultMet…
Browse files Browse the repository at this point in the history
…hod (#7)

The logic to detect if there are two conflicting default methods was incorrect.
If a class and its superclass both implement the same interface JPF should not
throw an IncompatibleClassChangeError.
  • Loading branch information
upthewaterspout authored and cyrille-artho committed May 17, 2018
1 parent fb15fd5 commit 18a0c42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/vm/ClassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ public MethodInfo getDefaultMethod (String uniqueName) {
for (ClassInfo ciIfc : ci.interfaces){
MethodInfo miIfc = ciIfc.getMethod(uniqueName, true);
if (miIfc != null && !miIfc.isAbstract()){
if (mi != null){
if (mi != null && !mi.equals(miIfc)){
// this has to throw a IncompatibleClassChangeError in the client since Java prohibits ambiguous default methods
String msg = "Conflicting default methods: " + mi.getFullName() + ", " + miIfc.getFullName();
throw new ClassChangeException(msg);
Expand Down
20 changes: 20 additions & 0 deletions src/tests/gov/nasa/jpf/test/vm/basic/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,24 @@ public int foo () {
assert a.foo() == 1 : "wrong A.foo() called for A1";
}
}


interface InterfaceWithDefaultMethod {
default int foo() {
return 42;
}
}

static class Base implements InterfaceWithDefaultMethod {
}

static class Child extends Base implements InterfaceWithDefaultMethod {
}

@Test
public void testDefaultMethodCall() {
if (verifyNoPropertyViolation()) {
assertEquals(42, new Child().foo());
}
}
}

0 comments on commit 18a0c42

Please sign in to comment.