Bug 566448 - [otdre] LoaderAwareClassWriter.getCommonSuperClass() chokes
on types from jdk.jdi
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/ASMByteCodeAnalyzer.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/ASMByteCodeAnalyzer.java
index da2781a..ab24045 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/ASMByteCodeAnalyzer.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/ASMByteCodeAnalyzer.java
@@ -48,6 +48,16 @@
 			this.superInterfaceNames = classReader.getInterfaces();
 		}
 
+		public ClassInformation(Class<?> clazz) {
+			this.modifiers = clazz.getModifiers();
+			this.superClassName = clazz.getSuperclass().getName().replace('.', '/');
+			Class<?>[] interfaces = clazz.getInterfaces();
+			this.superInterfaceNames = new String[interfaces.length];
+			for (int i = 0; i < interfaces.length; i++) {
+				this.superInterfaceNames[i] = interfaces[i].getName().replace('.', '/');
+			}
+		}
+
 		public boolean isInterface() {
 			return (modifiers & Opcodes.ACC_INTERFACE) != 0;
 		}
@@ -103,4 +113,19 @@
 		classInformationMap.put(className, classInformation);
 		return classInformation;
 	}
+
+	public ClassInformation getClassInformation(String className, ClassLoader loader) {
+		ClassInformation classInformation = classInformationMap.get(className);
+		if (classInformation != null) {
+			return classInformation;
+		}
+		try {
+			Class<?> clazz = loader.loadClass(className.replace('/', '.'));
+			if (clazz != null)
+				return new ClassInformation(clazz);
+		} catch (ClassNotFoundException e) {
+			return null;
+		}
+		return null;
+	}
 }
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/LoaderAwareClassWriter.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/LoaderAwareClassWriter.java
index 54fae60..501dd19 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/LoaderAwareClassWriter.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/LoaderAwareClassWriter.java
@@ -19,7 +19,9 @@
 
 import static org.eclipse.objectteams.otredyn.transformer.names.ClassNames.OBJECT_SLASH;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -60,16 +62,12 @@
 		ClassInformation ci2;
 		// need to load class bytes:
 		try {
-			try (InputStream s1 = this.loader.getResourceAsStream(type1+".class")) {
-				ci1 = this.analyzer.getClassInformation(s1, type1);
-				if (ci1 == null)
-					return OBJECT_SLASH;
-			}
-			try (InputStream s2 = this.loader.getResourceAsStream(type2+".class")) {
-				ci2 = this.analyzer.getClassInformation(s2, type2);
-				if (ci2 == null)
-					return OBJECT_SLASH;
-			}
+			ci1 = findClassInfo(type1);
+			if (ci1 == null)
+				return OBJECT_SLASH;
+			ci2 = findClassInfo(type2);
+			if (ci2 == null)
+				return OBJECT_SLASH;
 		} catch (Exception e) {
 		    throw new RuntimeException(e.toString());
 		}
@@ -116,6 +114,22 @@
         }
 	}
 
+	private ClassInformation findClassInfo(String type) throws MalformedURLException, IOException {
+		String className = type+".class";
+		try (InputStream stream = this.loader.getResourceAsStream(className)) {
+			if (stream != null)
+				return this.analyzer.getClassInformation(stream, type); 
+		}
+		/* FIXME: if we had a map package -> module, we could do like this: 
+		if (className.startsWith("com/sun/jdi")) {
+			try (InputStream stream2 = new URL("jrt:/jdk.jdi/"+className).openStream()) {
+				return this.analyzer.getClassInformation(stream2, type);
+			}
+		}
+		*/
+		return this.analyzer.getClassInformation(type, this.loader);
+	}
+
 	private List<String> getDirectSupersLayer(List<String> types, boolean classes) {
 		List<String> result = new ArrayList<String>();
 		for (String type : types) {
diff --git a/releng/build-scripts/build/test.xml b/releng/build-scripts/build/test.xml
index decd8a3..f9be2c9 100644
--- a/releng/build-scripts/build/test.xml
+++ b/releng/build-scripts/build/test.xml
@@ -70,7 +70,7 @@
             	--add-opens java.base/jdk.internal.ref=ALL-UNNAMED

             	--add-opens java.base/jdk.internal.math=ALL-UNNAMED

             	--add-opens java.base/jdk.internal.misc=ALL-UNNAMED

-            	-Djava.io.tmpdir=${test.tmpDir} -Dot.weaving=otdre -Dotequinox.weave.thread=base -javaagent:${otequinox.agent.jar}

+            	-Djava.io.tmpdir=${test.tmpDir} -Dot.weaving=otdre -javaagent:${otequinox.agent.jar}

             	-Dcompliance=1.7,1.8,12"/>

 		</ant>

 	</target>