Fixing a subtle bug: the method isParameterWithType() did not consider arbitrary...
[jpf-core.git] / src / main / gov / nasa / jpf / vm / Types.java
index c0edb793f6b50be7e2425f34571dda6231862d6b..ba71512c0b219217936e81a00cf803a0f7899476 100644 (file)
@@ -912,6 +912,13 @@ public class Types {
       return getTypeName(signature.substring(1)) + "[]";
     }
 
+    // If it does not contain '<' and '>' then it is
+    // a Type signature, e.g., T, U, etc.
+    if (Types.isParameterWithType(signature)) {
+      // Clean the ';' character first and return the Type
+      return Types.getTypeParameter(signature.replace(";", ""));
+    }
+
     int len1 = len-1;
     if (signature.charAt(len1) == ';') {
       // TODO: Fix for Groovy's model-checking
@@ -1105,7 +1112,7 @@ public class Types {
       return 1 + getTypeLength(signature, idx + 1);
 
     case 'L':
-
+    default:
       int semicolon = signature.indexOf(';', idx);
       // TODO: Fix for Groovy's model-checking
       // Check if this is a generic!
@@ -1132,7 +1139,7 @@ public class Types {
       return semicolon - idx + 1;
     }
 
-    throw new JPFException("invalid type signature");
+    //throw new JPFException("invalid type signature");
   }
 
   /**
@@ -1211,7 +1218,6 @@ public class Types {
     return arrTypeVarNames;
   }
 
-  // TODO: Fix for Groovy's model-checking
   public static String[] getParameterizedTypes(String signature) {
     int pos = signature.indexOf('<', 0);
     if (pos == -1)
@@ -1283,6 +1289,10 @@ public class Types {
   public static boolean isTypeParameter(String parameterizedType, String signature) {
     if (signature == null || signature.equals(""))
       return false;
+    // The comparison has to be done without the "[]" part if it is an array
+    if (Types.isArraySignature(parameterizedType)) {
+      parameterizedType = Types.getArrayClassName(parameterizedType);
+    }
     String typeParamSig = parameterizedType.concat(":");
     return signature.contains(typeParamSig);
   }
@@ -1302,6 +1312,14 @@ public class Types {
     return signature.replaceAll("\\+L|-L", "");
   }
 
+  public static boolean isParameterWithType(String signature) {
+    // Does not contain a class name
+    if (signature.charAt(0) != 'L' && !signature.contains(".") && !signature.contains("/")) {
+      return true;
+    }
+    return false;
+  }
+
   public static String getTypeParameter(String signature) {
     if (signature == null || signature.equals(""))
       return signature;
@@ -1311,7 +1329,6 @@ public class Types {
     }
 
     String cleanSig = signature.replaceAll("\\+|-", "");
-    // This kind of signature should be a repetition of its class' type parameter, e.g., TT for Class<T>
     if (cleanSig.length()%2 != 0) {
       // This is probably a class, e.g., +java.lang.Class
       return signature;