Fixing a few bugs in the statistics printout.
[jpf-core.git] / src / main / gov / nasa / jpf / vm / ClassInfo.java
index d9e5331835833c8f8e7635daf78b2f584eca2de3..3ff7ca6ca7c6d13a72e7dd1b551031168872f621 100644 (file)
@@ -1091,17 +1091,21 @@ public class ClassInfo extends InfoObject implements Iterable<MethodInfo>, Gener
   public MethodInfo getDefaultMethod (String uniqueName) {
     MethodInfo mi = null;
     
-    for (ClassInfo ci = this; ci != null; ci = ci.superClass){
-      for (ClassInfo ciIfc : ci.interfaces){
-        MethodInfo miIfc = ciIfc.getMethod(uniqueName, true);
-        if (miIfc != null && !miIfc.isAbstract()){
-          if (mi != null && !mi.equals(miIfc)){
+    for (ClassInfo ciIfc : this.getAllInterfaces()){
+      MethodInfo miIfc = ciIfc.getMethod(uniqueName, false);
+      if (miIfc != null && !miIfc.isAbstract() && !miIfc.isPrivate() && !miIfc.isStatic()){
+        if (mi != null && !mi.equals(miIfc)){
+          if(miIfc.getClassInfo().isSubInterfaceOf(mi.getClassInfo())) {
+            mi = miIfc;
+          } else if(mi.getClassInfo().isSubInterfaceOf(miIfc.getClassInfo())) {
+            continue;
+          } else {
             // 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);
-          } else {
-            mi = miIfc;
           }
+        } else {
+          mi = miIfc;
         }
       }
     }
@@ -1109,6 +1113,11 @@ public class ClassInfo extends InfoObject implements Iterable<MethodInfo>, Gener
     return mi;
   }
   
+  private boolean isSubInterfaceOf(ClassInfo classInfo) {
+    assert this.isInterface() && classInfo.isInterface();
+    return this == classInfo || this.getAllInterfaces().contains(classInfo);
+  }
+
   /**
    * This retrieves the SAM from this functional interface. Note that this is only
    * called on functional interface expecting to have a SAM. This shouldn't expect 
@@ -1804,6 +1813,12 @@ public class ClassInfo extends InfoObject implements Iterable<MethodInfo>, Gener
   public static boolean isBuiltinClass (String cname) {
     char c = cname.charAt(0);
 
+    // TODO: Fix for Groovy's model-checking
+    // TODO: Handling impossible names in Groovy, e.g., [Ljava.lang.Object;BeanInfo
+    if (cname.indexOf(';') != -1 && cname.indexOf(';') != cname.length() - 1) {
+      return false;
+    }
+
     // array class
     if ((c == '[') || cname.endsWith("[]")) {
       return true;
@@ -2589,6 +2604,15 @@ public class ClassInfo extends InfoObject implements Iterable<MethodInfo>, Gener
   public DirectCallStackFrame createRunStartStackFrame (ThreadInfo ti, MethodInfo miRun){
     return null;
   }
+
+  // TODO: Fix for Groovy's model-checking
+  public String[] getGenericTypeVariableNames () {
+    if (genericSignature == null || genericSignature.equals(""))
+      return new String[0];
+    if (!genericSignature.contains(":"))
+      return new String[0];
+    return Types.getGenericTypeVariableNames(genericSignature);
+  }
 }