Migrate to using org.apache.bcel 5.2 from Orbit.
These changes have been drafted at svn.objectteams.org as:
 r23513, r23514, r23515, r23522, r23527, r23530, r23567, r23568, r23569, r23570, r23625, r23642
diff --git a/othersrc/OTRE/.classpath b/othersrc/OTRE/.classpath
index b98640e..3532c74 100644
--- a/othersrc/OTRE/.classpath
+++ b/othersrc/OTRE/.classpath
@@ -2,6 +2,6 @@
 <classpath>
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
-	<classpathentry combineaccessrules="false" kind="src" path="/bcel4-4-1"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/org.apache.bcel"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/othersrc/OTRE/otre_min.jardesc b/othersrc/OTRE/otre_min.jardesc
index 73086e6..9eded8f 100644
--- a/othersrc/OTRE/otre_min.jardesc
+++ b/othersrc/OTRE/otre_min.jardesc
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <jardesc>
-    <jar path="org.objectteams.otdt/lib/otre_min.jar"/>
+    <jar path="org.eclipse.objectteams.otdt/lib/otre_min.jar"/>
     <options buildIfNeeded="true" compress="true" descriptionLocation="/OTRE/otre_min.jardesc" exportErrors="false" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
     <storedRefactorings deprecationInfo="true" structuralOnly="false"/>
     <selectedProjects/>
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseCallRedirection.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseCallRedirection.java
index 567a422..709592c 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseCallRedirection.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseCallRedirection.java
@@ -16,9 +16,9 @@
  **********************************************************************/
 package org.eclipse.objectteams.otre;
 
-import de.fub.bytecode.classfile.*;
-import de.fub.bytecode.generic.*;
-import de.fub.bytecode.*;
+import org.apache.bcel.classfile.*;
+import org.apache.bcel.generic.*;
+import org.apache.bcel.*;
 
 import java.util.*;
 
@@ -155,7 +155,7 @@
 
 		ConstantPoolGen cpg = cg.getConstantPool();
 		String class_name = cg.getClassName();
-		MethodGen mg = new MethodGen(m, class_name, cpg);
+		MethodGen mg = newMethodGen(m, class_name, cpg);
 		
 		if (isTSuperWrapper(mg)) {
 			// tsuper wrapper do not need base call surrogates
@@ -438,7 +438,7 @@
         String class_name   = cg.getClassName();
         String method_name  = m.getName();
 
-        MethodGen mg = new MethodGen(m, class_name, cpg);
+        MethodGen mg = newMethodGen(m, class_name, cpg);
 
 		Type[]   argumentTypes         = mg.getArgumentTypes();
         Type     returnType            = mg.getReturnType();
@@ -1438,7 +1438,7 @@
 /*
  * (non-Javadoc)
  * 
- * @see org.eclipse.objectteams.otre.common.ObjectTeamsTransformation#doTransformCode(de.fub.bytecode.generic.ClassGen)
+ * @see org.eclipse.objectteams.otre.common.ObjectTeamsTransformation#doTransformCode(org.apache.bcel.generic.ClassGen)
  */
     public void doTransformCode(ClassGen cg) {
         // nothing to do
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseMethodTransformation.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseMethodTransformation.java
index 06878cb..89a4854 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseMethodTransformation.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseMethodTransformation.java
@@ -35,50 +35,50 @@
 import org.eclipse.objectteams.otre.util.MethodBinding;
 import org.eclipse.objectteams.otre.util.TeamIdDispenser;
 
-import de.fub.bytecode.Constants;
-import de.fub.bytecode.classfile.Field;
-import de.fub.bytecode.classfile.LineNumber;
-import de.fub.bytecode.classfile.LineNumberTable;
-import de.fub.bytecode.classfile.Method;
-import de.fub.bytecode.generic.AASTORE;
-import de.fub.bytecode.generic.ACONST_NULL;
-import de.fub.bytecode.generic.ALOAD;
-import de.fub.bytecode.generic.ANEWARRAY;
-import de.fub.bytecode.generic.ARRAYLENGTH;
-import de.fub.bytecode.generic.ATHROW;
-import de.fub.bytecode.generic.ArrayType;
-import de.fub.bytecode.generic.BasicType;
-import de.fub.bytecode.generic.BranchInstruction;
-import de.fub.bytecode.generic.ClassGen;
-import de.fub.bytecode.generic.ConstantPoolGen;
-import de.fub.bytecode.generic.DUP;
-import de.fub.bytecode.generic.DUP_X1;
-import de.fub.bytecode.generic.FieldGen;
-import de.fub.bytecode.generic.GOTO;
-import de.fub.bytecode.generic.IADD;
-import de.fub.bytecode.generic.ICONST;
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Field;
+import org.apache.bcel.classfile.LineNumber;
+import org.apache.bcel.classfile.LineNumberTable;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.AASTORE;
+import org.apache.bcel.generic.ACONST_NULL;
+import org.apache.bcel.generic.ALOAD;
+import org.apache.bcel.generic.ANEWARRAY;
+import org.apache.bcel.generic.ARRAYLENGTH;
+import org.apache.bcel.generic.ATHROW;
+import org.apache.bcel.generic.ArrayType;
+import org.apache.bcel.generic.BasicType;
+import org.apache.bcel.generic.BranchInstruction;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.DUP;
+import org.apache.bcel.generic.DUP_X1;
+import org.apache.bcel.generic.FieldGen;
+import org.apache.bcel.generic.GOTO;
+import org.apache.bcel.generic.IADD;
+import org.apache.bcel.generic.ICONST;
 
-import de.fub.bytecode.generic.IFNE;
-import de.fub.bytecode.generic.IFNONNULL;
-import de.fub.bytecode.generic.IF_ICMPLT;
-import de.fub.bytecode.generic.IINC;
-import de.fub.bytecode.generic.INVOKESPECIAL;
-import de.fub.bytecode.generic.Instruction;
-import de.fub.bytecode.generic.InstructionConstants;
-import de.fub.bytecode.generic.InstructionFactory;
-import de.fub.bytecode.generic.InstructionHandle;
-import de.fub.bytecode.generic.InstructionList;
-import de.fub.bytecode.generic.InvokeInstruction;
-import de.fub.bytecode.generic.LDC;
-import de.fub.bytecode.generic.LocalVariableGen;
-import de.fub.bytecode.generic.MONITOREXIT;
-import de.fub.bytecode.generic.MethodGen;
-import de.fub.bytecode.generic.NOP;
-import de.fub.bytecode.generic.ObjectType;
-import de.fub.bytecode.generic.POP;
-import de.fub.bytecode.generic.PUSH;
-import de.fub.bytecode.generic.TABLESWITCH;
-import de.fub.bytecode.generic.Type;
+import org.apache.bcel.generic.IFNE;
+import org.apache.bcel.generic.IFNONNULL;
+import org.apache.bcel.generic.IF_ICMPLT;
+import org.apache.bcel.generic.IINC;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.Instruction;
+import org.apache.bcel.generic.InstructionConstants;
+import org.apache.bcel.generic.InstructionFactory;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.InvokeInstruction;
+import org.apache.bcel.generic.LDC;
+import org.apache.bcel.generic.LocalVariableGen;
+import org.apache.bcel.generic.MONITOREXIT;
+import org.apache.bcel.generic.MethodGen;
+import org.apache.bcel.generic.NOP;
+import org.apache.bcel.generic.ObjectType;
+import org.apache.bcel.generic.POP;
+import org.apache.bcel.generic.PUSH;
+import org.apache.bcel.generic.TABLESWITCH;
+import org.apache.bcel.generic.Type;
 
 
 /**
@@ -197,7 +197,7 @@
 	{
         if (m.isAbstract() || m.isNative())
             return null;
-		MethodGen mg = new MethodGen(m, className, cpg);
+		MethodGen mg = newMethodGen(m, className, cpg);
 		String method_name = m.getName();
 		InstructionHandle[] ihs = mg.getInstructionList().getInstructionHandles();
 		boolean found = false;
@@ -355,7 +355,7 @@
     		MethodBinding match= matchingBinding(inheritedBindings, m, false);
     		if (bindingsForMethod != null || (match!= null && !m.isStatic() && !m.isPrivate())) {
     			
-    			mg = new MethodGen(m, class_name, cpg);
+    			mg = newMethodGen(m, class_name, cpg);
     			Method orig_method;
 					
     			String name_orig = genOrigMethName(method_name);
@@ -493,7 +493,6 @@
 		}
 		if (debugging) {
 			mg.removeLocalVariables();
-			mg.removeLocalVariableTypes();
 			int slot = 0;
 			// create local variable table for "this" and arguments:
 			if (!m.isAbstract())
@@ -1733,7 +1732,7 @@
 		{
 			ObjectType actualObj = (ObjectType)actual;
 			ObjectType formalObj = (ObjectType)formal;
-			if (actualObj.subclassOf(formalObj))
+			if (RepositoryAccess.safeSubclassOf(actualObj, formalObj))
 				return formalObj;
 		}
 		return actual;
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseTagInsertion.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseTagInsertion.java
index ebbf234..5f0b4dd 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseTagInsertion.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/BaseTagInsertion.java
@@ -16,8 +16,8 @@
  **********************************************************************/
 package org.eclipse.objectteams.otre;
 
-import de.fub.bytecode.generic.*;
-import de.fub.bytecode.*;
+import org.apache.bcel.generic.*;
+import org.apache.bcel.*;
 
 
 import java.util.*;
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/ClassEnhancer.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/ClassEnhancer.java
index aa80c98..ce12bb7 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/ClassEnhancer.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/ClassEnhancer.java
@@ -16,10 +16,10 @@
  **********************************************************************/
 package org.eclipse.objectteams.otre;
 
-import de.fub.bytecode.classfile.Field;
-import de.fub.bytecode.classfile.Method;
-import de.fub.bytecode.generic.ClassGen;
-import de.fub.bytecode.generic.ConstantPoolGen;
+import org.apache.bcel.classfile.Field;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.ConstantPoolGen;
 
 
 
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/Decapsulation.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/Decapsulation.java
index 9f74123..e34f221 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/Decapsulation.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/Decapsulation.java
@@ -25,15 +25,15 @@
 import org.eclipse.objectteams.otre.util.FieldDescriptor;
 import org.eclipse.objectteams.otre.util.SuperMethodDescriptor;
 
-import de.fub.bytecode.Constants;
-import de.fub.bytecode.classfile.Method;
-import de.fub.bytecode.generic.ClassGen;
-import de.fub.bytecode.generic.ConstantPoolGen;
-import de.fub.bytecode.generic.InstructionFactory;
-import de.fub.bytecode.generic.InstructionList;
-import de.fub.bytecode.generic.MethodGen;
-import de.fub.bytecode.generic.ObjectType;
-import de.fub.bytecode.generic.Type;
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.InstructionFactory;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.MethodGen;
+import org.apache.bcel.generic.ObjectType;
+import org.apache.bcel.generic.Type;
 
 /**
  *  For each base method that is bound by callout and has
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/LiftingParticipantTransformation.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/LiftingParticipantTransformation.java
index 48e949d..9c10f81 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/LiftingParticipantTransformation.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/LiftingParticipantTransformation.java
@@ -19,26 +19,26 @@
 
 import org.objectteams.Team;
 
-import de.fub.bytecode.Constants;
-import de.fub.bytecode.classfile.Method;
-import de.fub.bytecode.generic.ALOAD;
-import de.fub.bytecode.generic.BranchInstruction;
-import de.fub.bytecode.generic.ClassGen;
-import de.fub.bytecode.generic.ConstantPoolGen;
-import de.fub.bytecode.generic.DUP;
-import de.fub.bytecode.generic.GOTO;
-import de.fub.bytecode.generic.IFNULL;
-import de.fub.bytecode.generic.INVOKESPECIAL;
-import de.fub.bytecode.generic.InstructionFactory;
-import de.fub.bytecode.generic.InstructionHandle;
-import de.fub.bytecode.generic.InstructionList;
-import de.fub.bytecode.generic.LDC;
-import de.fub.bytecode.generic.MethodGen;
-import de.fub.bytecode.generic.NEW;
-import de.fub.bytecode.generic.NOP;
-import de.fub.bytecode.generic.ObjectType;
-import de.fub.bytecode.generic.POP;
-import de.fub.bytecode.generic.Type;
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.ALOAD;
+import org.apache.bcel.generic.BranchInstruction;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.DUP;
+import org.apache.bcel.generic.GOTO;
+import org.apache.bcel.generic.IFNULL;
+import org.apache.bcel.generic.INVOKESPECIAL;
+import org.apache.bcel.generic.InstructionFactory;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.LDC;
+import org.apache.bcel.generic.MethodGen;
+import org.apache.bcel.generic.NEW;
+import org.apache.bcel.generic.NOP;
+import org.apache.bcel.generic.ObjectType;
+import org.apache.bcel.generic.POP;
+import org.apache.bcel.generic.Type;
 
 /**
  * If the property ot.lifting.participant is set transform all lift methods and insert 
@@ -107,7 +107,7 @@
 	}
 
 	private Method weaveLiftingParticipant(Method m, String className, ConstantPoolGen cpg) {
-		MethodGen mg = new MethodGen(m, className, cpg);
+		MethodGen mg = newMethodGen(m, className, cpg);
 		InstructionList il = mg.getInstructionList();
 		InstructionHandle[] ihs = il.getInstructionHandles();
 		for (int i=0; i<ihs.length; i++) {
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/LowerableTransformation.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/LowerableTransformation.java
index 1db8d9f..52c6726 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/LowerableTransformation.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/LowerableTransformation.java
@@ -19,10 +19,10 @@
 import java.util.HashSet;
 import java.util.Set;
 
-import de.fub.bytecode.Constants;
-import de.fub.bytecode.generic.ClassGen;
-import de.fub.bytecode.generic.MethodGen;
-import de.fub.bytecode.generic.Type;
+import org.apache.bcel.Constants;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.MethodGen;
+import org.apache.bcel.generic.Type;
 
 /**
  * This transformer helps legacy class files pre 1.3.2 to cope with changes re ILowerable.lower().
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/OTConstants.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/OTConstants.java
index d207abd..ea291a8 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/OTConstants.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/OTConstants.java
@@ -16,7 +16,7 @@
  **********************************************************************/
 package org.eclipse.objectteams.otre;
 
-import de.fub.bytecode.generic.*;
+import org.apache.bcel.generic.*;
 
 
 /**
@@ -47,9 +47,9 @@
     ObjectType liftingVeto   = new ObjectType("org.objectteams.LiftingVetoException");
     /**                            Type <tt>org.eclipse.objectteams.otre.OTREInternalError</tt> */	
     ObjectType internalError = new ObjectType("org.eclipse.objectteams.otre.OTREInternalError");
-	/**                            Type <tt>org.eclipse.objectteams.otre.OTREInternalError</tt> */	
+	/**                            Type <tt>org.objectteams.ResultNotProvidedError</tt> */	
 	ObjectType notProvidedError = new ObjectType("org.objectteams.ResultNotProvidedError");
-	/**                            Type <tt>org.eclipse.objectteams.otre.UnsupportedFeatureException</tt> */	
+	/**                            Type <tt>org.objectteams.UnsupportedFeatureException</tt> */	
 	ObjectType unsupportedFeature = new ObjectType("org.objectteams.UnsupportedFeatureException");
 	
 	ObjectType threadType  = new ObjectType("java.lang.Thread");
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/ObjectTeamsTransformation.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/ObjectTeamsTransformation.java
index 7158659..121f57c 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/ObjectTeamsTransformation.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/ObjectTeamsTransformation.java
@@ -34,18 +34,18 @@
 import org.eclipse.objectteams.otre.util.CallinBindingManager;
 import org.eclipse.objectteams.otre.util.RoleBaseBinding;
 
-import de.fub.bytecode.Constants;
-import de.fub.bytecode.Repository;
-import de.fub.bytecode.classfile.Attribute;
-import de.fub.bytecode.classfile.Constant;
-import de.fub.bytecode.classfile.ConstantUtf8;
-import de.fub.bytecode.classfile.InnerClass;
-import de.fub.bytecode.classfile.InnerClasses;
-import de.fub.bytecode.classfile.JavaClass;
-import de.fub.bytecode.classfile.LineNumberTable;
-import de.fub.bytecode.classfile.Method;
-import de.fub.bytecode.classfile.Unknown;
-import de.fub.bytecode.generic.*;
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Attribute;
+import org.apache.bcel.classfile.Constant;
+import org.apache.bcel.classfile.ConstantUtf8;
+import org.apache.bcel.classfile.InnerClass;
+import org.apache.bcel.classfile.InnerClasses;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.LineNumberTable;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.classfile.StackMap;
+import org.apache.bcel.classfile.Unknown;
+import org.apache.bcel.generic.*;
 
 /**
  * Superclass for all transformations in this package.
@@ -665,7 +665,7 @@
     		return; // no main method in the first loaded class...
     	}
     	
-    	MethodGen mainMethod = new MethodGen(main, main_class_name, cpg);
+    	MethodGen mainMethod = newMethodGen(main, main_class_name, cpg);
     	InstructionList il = mainMethod.getInstructionList();
     	
     	int startLine = -1;
@@ -685,8 +685,10 @@
     		Iterator<String> teamIt = teamsToInitialize.iterator();
     		while (teamIt.hasNext()) {
     			String nextTeam = teamIt.next();
-    			JavaClass teamClass = Repository.lookupClass(nextTeam);
-    			if (teamClass == null) {
+    			JavaClass teamClass = null;
+    			try {
+    				teamClass = RepositoryAccess.lookupClass(nextTeam);
+    			} catch (ClassNotFoundException cfne) {
     				System.err.println("Config error: Team class '"+nextTeam+ "' in config file '"+ TEAM_CONFIG_FILE+"' can not be found!");
     				System.err.println("Main class = "+main_class_name+
     									", class loader = "+(this.loader!=null?this.loader.getClass().getName():"null")+
@@ -1372,6 +1374,18 @@
 		return superRoleNames;	
 	}*/
     
+    /** Create a MethodGen and remove some unwanted code attributes (which would need special translation which we don't have) */
+    protected static MethodGen newMethodGen(Method m, String class_name, ConstantPoolGen cp) {
+    	MethodGen mg = new MethodGen(m, class_name, cp);
+    	List<Attribute> attributesToRemove = new ArrayList<Attribute>();
+    	for (Attribute attr : mg.getCodeAttributes())
+    		if (attr instanceof Unknown || attr instanceof StackMap)
+    			attributesToRemove.add(attr);
+		for (Attribute attr : attributesToRemove)
+			mg.removeCodeAttribute(attr);
+    	return mg;
+    }
+    
     /**
      * Remove all contents of a method as preparation for adding a new implementation
 	 *
@@ -1387,9 +1401,9 @@
         mg.getInstructionList().dispose(); //throw away the old implementation
         mg.removeLineNumbers();
         mg.removeLocalVariables();
-        mg.removeLocalVariableTypes();
         mg.removeExceptionHandlers();
         mg.removeAttributes();
+        mg.removeCodeAttributes();
         return mg;
     }
     
@@ -1403,7 +1417,7 @@
 	 */
 	static void addToConstructor(Method m, InstructionList addedCode, ClassGen cg, ConstantPoolGen cpg) {
 		String class_name = cg.getClassName();
-		MethodGen mg = new MethodGen(m, class_name, cpg);
+		MethodGen mg = newMethodGen(m, class_name, cpg);
 		InstructionList il = mg.getInstructionList().copy();
 		InstructionHandle[] ihs = il.getInstructionHandles();
 
@@ -1786,7 +1800,7 @@
 			nestingDepth = countOccurrences(className, '$') - 1;
 			targetName = outerClass.getClassName();
 		}
-		MethodGen mg = new MethodGen(m, className, cpg);
+		MethodGen mg = newMethodGen(m, className, cpg);
 		InstructionList il = mg.getInstructionList();
 		InstructionList prefix = new InstructionList();
 		InstructionHandle try_start = il.getStart();
@@ -1814,20 +1828,7 @@
 				Constants.INVOKEVIRTUAL));
 		// <-- new implicit deactivation
 
-		FindPattern findPattern = new FindPattern(il);
-		String pat = "`ReturnInstruction'";
-		InstructionHandle ih = findPattern.search(pat);
-		while (ih != null) {
-			// insert deactivate-call before return instruction in ih:
-			InstructionList postfixCopy = postfix.copy();
-			if (debugging)
-				mg.addLineNumber(postfixCopy.getStart(), STEP_OVER_LINENUMBER);
-			InstructionHandle inserted = il.insert(ih, postfixCopy); // instruction lists can not be reused
-			il.redirectBranches(ih, inserted); // SH: retarget all jumps that targeted at the return instruction
-			if (ih.getNext() == null)
-				break; // end of instruction list reached
-			ih = findPattern.search(pat, ih.getNext());
-		}
+		insertBeforeReturn(mg, il, postfix);
 
 		/**
 		 * **** add an exception handler which calls deactivate before throwing
@@ -2256,4 +2257,30 @@
 	  	checkLoaded.setTarget(il.append(new NOP()));
 	  	return start;
 	}
+
+	@SuppressWarnings("unchecked")
+	public static void insertBeforeReturn(MethodGen mg, InstructionList il, InstructionList insertion) {
+		// InstructionFinder is broken see https://issues.apache.org/bugzilla/show_bug.cgi?id=40044
+		// which is fixed in r516724 (2007-03-10) but latest release bcel 5.2 is 6. June 2006.
+//		Iterator<InstructionHandle[]> ihIt = new InstructionFinder(il).search("ReturnInstruction");
+//		while (ihIt.hasNext()) {
+//			InstructionHandle[] ihAr = ihIt.next();
+//			InstructionList insertionCopy = insertion.copy();
+//			if (debugging)
+//				mg.addLineNumber(insertionCopy.getStart(), STEP_OVER_LINENUMBER);
+//			InstructionHandle inserted = il.insert(ihAr[0], insertionCopy); // instruction lists can not be reused
+//			il.redirectBranches(ihAr[0], inserted);// SH: retarget all jumps that targeted at the return instruction
+//		}
+		Iterator<InstructionHandle>ihIt = il.iterator();
+		while (ihIt.hasNext()) {
+			InstructionHandle ihAr = ihIt.next();
+			if (!(ihAr.getInstruction() instanceof ReturnInstruction))
+				continue;
+			InstructionList insertionCopy = insertion.copy();
+			if (debugging)
+				mg.addLineNumber(insertionCopy.getStart(), STEP_OVER_LINENUMBER);
+			InstructionHandle inserted = il.insert(ihAr, insertionCopy); // instruction lists can not be reused
+			il.redirectBranches(ihAr, inserted);// SH: retarget all jumps that targeted at the return instruction
+		}
+	}
 }
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/RepositoryAccess.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/RepositoryAccess.java
new file mode 100644
index 0000000..590a658
--- /dev/null
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/RepositoryAccess.java
@@ -0,0 +1,122 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ * 
+ * Copyright 2010 Stephan Herrmann
+ * 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * $Id$
+ * 
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ * 
+ * Contributors:
+ * 		Stephan Herrmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otre;
+
+import java.util.HashMap;
+
+import org.apache.bcel.Repository;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.generic.ObjectType;
+import org.apache.bcel.util.ClassLoaderRepository;
+
+/** 
+ * Provides a classloader aware access to one or more class repositories.
+ * All access methods are static, but context is passed by setting a per-thread
+ * current repository using {@link #setClassLoader(ClassLoader)}.
+ * @since 0.7.0 
+ */
+public class RepositoryAccess {
+
+	/** One class repository per class loader. */
+	private static HashMap<ClassLoader,ClassLoaderRepository> repositories = new HashMap<ClassLoader,ClassLoaderRepository>();
+	/** One current repository per thread. */
+	private static ThreadLocal<ClassLoaderRepository> currentRepository = new ThreadLocal<ClassLoaderRepository>();
+	 
+	/** 
+	 * Setup a repository for the given class loader and make it the current repository for the current thread.
+	 * @param loader class loader, may be null
+	 * @return the previously active class repository for this thread
+	 */
+	public static synchronized ClassLoaderRepository setClassLoader(ClassLoader loader) {
+		ClassLoaderRepository clr = null;
+		if (loader != null) { // avoid creating ClassLoaderRepository with null loader
+			clr = repositories.get(loader);
+			if (clr == null)
+				repositories.put(loader, clr = new ClassLoaderRepository(loader));
+		}
+		ClassLoaderRepository prev = currentRepository.get();
+		currentRepository.set(clr);
+		return prev;
+	}
+	 
+	/** Reset the class repository for the current thread. */
+	public static synchronized void resetRepository(ClassLoaderRepository repository) {
+		currentRepository.set(repository);
+	}
+	 
+	public static JavaClass lookupClass(String className)
+	 		throws ClassNotFoundException 
+	{
+		ClassLoaderRepository clr = currentRepository.get();
+		if (clr != null)
+			return clr.loadClass(className);
+		return Repository.lookupClass(className);
+	}
+
+	public static JavaClass[] getSuperClasses(String className) 
+			throws ClassNotFoundException 
+	{
+		 ClassLoaderRepository clr = currentRepository.get();
+		 JavaClass jc;
+		 if (clr != null)
+			 jc = clr.loadClass(className);
+		 else
+			 jc = Repository.lookupClass(className);
+		 return jc.getSuperClasses();
+	}
+
+	public static boolean implementationOf(String className, String ifcName) 
+			throws ClassNotFoundException 
+	{
+		ClassLoaderRepository clr = currentRepository.get();
+		JavaClass jc, ifc;
+		if (clr != null) {
+			jc = clr.loadClass(className);
+			ifc= clr.loadClass(ifcName);
+		} else {
+			jc = Repository.lookupClass(className);
+			ifc= Repository.lookupClass(ifcName);
+		}
+		return jc.implementationOf(ifc);
+	}
+
+	public static boolean safeSubclassOf(ObjectType subClass, ObjectType superClass) {
+		try {
+			String subClassName = subClass.getClassName();
+			String superClassName = superClass.getClassName();
+			return instanceOf(subClassName, superClassName);
+		} catch (ClassNotFoundException e) {
+			// consider classes as incommensurable if they can't both be loaded in the current class loader
+			return false;
+		}
+	}
+
+	protected static boolean instanceOf(String subClassName, String superClassName) 
+			throws ClassNotFoundException 
+	{
+		ClassLoaderRepository clr = currentRepository.get();
+		JavaClass subJClass, superJClass;
+		if (clr != null) {
+			subJClass = clr.loadClass(subClassName);
+			superJClass= clr.loadClass(superClassName);
+		} else {
+			subJClass = Repository.lookupClass(subClassName);
+			superJClass= Repository.lookupClass(superClassName);
+		}
+		return subJClass.instanceOf(superJClass);
+	}
+}
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/StaticSliceBaseTransformation.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/StaticSliceBaseTransformation.java
index 3525912..6ba98ae 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/StaticSliceBaseTransformation.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/StaticSliceBaseTransformation.java
@@ -16,9 +16,9 @@
  **********************************************************************/
 package org.eclipse.objectteams.otre;
 
-import de.fub.bytecode.classfile.*;
-import de.fub.bytecode.generic.*;
-import de.fub.bytecode.*;
+import org.apache.bcel.classfile.*;
+import org.apache.bcel.generic.*;
+import org.apache.bcel.*;
 
 import org.eclipse.objectteams.otre.util.*;
 
@@ -706,7 +706,7 @@
 		 /* The clinit method always exists at this moment, because it has been added 
          * by the interface transformer part of this transformer if necessary.
          */
-		MethodGen mg = new MethodGen(clinitMethod, cg.getClassName(), cpg);
+		MethodGen mg = newMethodGen(clinitMethod, cg.getClassName(), cpg);
 		InstructionList il = mg.getInstructionList();
 		// add static initialization for added static fields at start of the <clinit> method:
 		il.insert(inizializeStaticFields(cg.getClassName()));
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/SubBoundBaseMethodRedefinition.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/SubBoundBaseMethodRedefinition.java
index 104374d..e107fda 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/SubBoundBaseMethodRedefinition.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/SubBoundBaseMethodRedefinition.java
@@ -16,9 +16,9 @@
  **********************************************************************/
 package org.eclipse.objectteams.otre;
 
-import de.fub.bytecode.classfile.*;
-import de.fub.bytecode.generic.*;
-import de.fub.bytecode.*;
+import org.apache.bcel.classfile.*;
+import org.apache.bcel.generic.*;
+import org.apache.bcel.*;
 
 import java.util.*;
 
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/TeamInterfaceImplementation.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/TeamInterfaceImplementation.java
index faa7cd1..de2c850 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/TeamInterfaceImplementation.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/TeamInterfaceImplementation.java
@@ -16,9 +16,9 @@
  **********************************************************************/
 package org.eclipse.objectteams.otre;
 
-import de.fub.bytecode.classfile.*;
-import de.fub.bytecode.generic.*;
-import de.fub.bytecode.*;
+import org.apache.bcel.classfile.*;
+import org.apache.bcel.generic.*;
+import org.apache.bcel.*;
 
 import java.util.*;
 
@@ -110,7 +110,7 @@
 			ConstantPoolGen cpg) {
 		Method clinitMethod = cg.containsMethod(
 				Constants.STATIC_INITIALIZER_NAME, "()V");
-		MethodGen mg = new MethodGen(clinitMethod, cg.getClassName(), cpg);
+		MethodGen mg = newMethodGen(clinitMethod, cg.getClassName(), cpg);
 		InstructionList il = mg.getInstructionList();
 
 		InstructionList addedInitialization = new InstructionList();
@@ -269,7 +269,7 @@
 	 * @param cpg
 	 */
 	private void addToMethodStart(InstructionList additionalInstructions, Method method, ClassGen cg, ConstantPoolGen cpg) {
-		MethodGen mg = new MethodGen(method, cg.getClassName(), cpg);
+		MethodGen mg = newMethodGen(method, cg.getClassName(), cpg);
 		InstructionList il = mg.getInstructionList();
 		il.insert(additionalInstructions);
 		mg.setMaxStack();
@@ -349,6 +349,8 @@
 			
 			il.append(factory.createFieldAccess(class_name, "_OT$ID", Type.INT,
 					Constants.GETSTATIC));
+			// Note: the method _OT$addTeam may be found in a super classes (topmostBoundBase),
+			//       but we'll simply leave this lookup to the VM 
 			il.append(factory.createInvoke(actBase, "_OT$addTeam", Type.VOID,
 					new Type[] { teamType, Type.INT }, Constants.INVOKESTATIC));
 			// generated: <actBase>._OT$addTeam(this, _OT$ID);
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/ThreadActivation.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/ThreadActivation.java
index 7ac2e1e..88ab778 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/ThreadActivation.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/ThreadActivation.java
@@ -18,10 +18,11 @@
 
 import java.util.HashSet;
 
-import de.fub.bytecode.classfile.*;
-import de.fub.bytecode.generic.*;
-import de.fub.bytecode.*;
+import org.apache.bcel.classfile.*;
+import org.apache.bcel.generic.*;
+import org.apache.bcel.*;
 
+import static org.eclipse.objectteams.otre.ObjectTeamsTransformation.newMethodGen;
 
 /**
  * This transformer inserts a notification call to the TeamThreadManager at the 
@@ -47,13 +48,13 @@
 		String class_name = cg.getClassName();
 		// check if this class is a subtype of Thread or Runnable:
 		try {
-			return Repository.implementationOf(class_name, "java.lang.Runnable") || Repository.instanceOf(class_name, "java.lang.Thread");
-		} catch (NullPointerException npe) {
+			return RepositoryAccess.implementationOf(class_name, "java.lang.Runnable") || RepositoryAccess.instanceOf(class_name, "java.lang.Thread");
+		} catch (ClassNotFoundException cfne) {
 			if (ObjectTeamsTransformation.WORKAROUND_REPOSITORY) {
 				return false;
 			}
 			else
-				throw npe; // rethrow
+				throw new RuntimeException("Could not find class being loaded", cfne); // rethrow
 		}
 	}
 	public void doTransformInterface(ClassEnhancer enhancer, ClassGen cg) {
@@ -93,7 +94,7 @@
 
 		Method runMethode = cg.containsMethod("run", "()V"); // existence checked in transformInterface
 
-		MethodGen mg = new MethodGen(runMethode, class_name, cpg);
+		MethodGen mg = newMethodGen(runMethode, class_name, cpg);
 		InstructionList il = mg.getInstructionList();
 		InstructionHandle try_start = il.getStart();
 		
@@ -123,18 +124,7 @@
 				 Constants.INVOKESTATIC));
 		ifIsThreadStarted.setTarget(threadDeactivation.append(new NOP()));
 
-		FindPattern findPattern = new FindPattern(il);
-		String pat = "`ReturnInstruction'";
-		InstructionHandle ih = findPattern.search(pat);
-		while (ih != null) {
-			// insert deactivate-call before return instruction in ih:
-			InstructionList deactivationCopy = threadDeactivation.copy();
-			InstructionHandle inserted = il.insert(ih, deactivationCopy); // instruction lists can not be reused
-			il.redirectBranches(ih, inserted);// SH: retarget all jumps that targeted at the return instruction
-			if (ih.getNext() == null)
-				break; // end of instruction list reached
-			ih = findPattern.search(pat, ih.getNext());
-		}
+		ObjectTeamsTransformation.insertBeforeReturn(mg, il, threadDeactivation);
 
 		/** **** Add an exception handler which calls TeamThreadManager.threadEnded() *****
 		 * ***** before throwing the exception (finaly-simulation): 											        */
@@ -163,7 +153,7 @@
 			return null;
 		String className = cg.getClassName();
 		ConstantPoolGen cpg = cg.getConstantPool();
-		MethodGen mg = new MethodGen(method, className, cpg);
+		MethodGen mg = newMethodGen(method, className, cpg);
 		InstructionList il = mg.getInstructionList();
 		InstructionHandle ih = il.getStart();
 		while (ih != null && ih.getInstruction().getOpcode() != Constants.INVOKESPECIAL) {
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/jplis/JPLISEnhancer.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/jplis/JPLISEnhancer.java
index e390663..10d2c7d 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/jplis/JPLISEnhancer.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/jplis/JPLISEnhancer.java
@@ -24,14 +24,14 @@
 import org.eclipse.objectteams.otre.OTREInternalError;
 import org.eclipse.objectteams.otre.ObjectTeamsTransformation;
 
-import de.fub.bytecode.Constants;
-import de.fub.bytecode.classfile.ClassParser;
-import de.fub.bytecode.classfile.Field;
-import de.fub.bytecode.classfile.Method;
-import de.fub.bytecode.classfile.Utility;
-import de.fub.bytecode.generic.ClassGen;
-import de.fub.bytecode.generic.ConstantPoolGen;
-import de.fub.bytecode.generic.MethodGen;
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.ClassParser;
+import org.apache.bcel.classfile.Field;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.classfile.Utility;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.MethodGen;
 
 
 /**
@@ -51,14 +51,14 @@
 	}
 	
 	/* (non-Javadoc)
-	 * @see org.eclipse.objectteams.otre.ClassEnhancer#addImplements(java.lang.String, de.fub.bytecode.generic.ClassGen)
+	 * @see org.eclipse.objectteams.otre.ClassEnhancer#addImplements(java.lang.String, org.apache.bcel.generic.ClassGen)
 	 */
 	public void addImplements(String interfaceName, ClassGen cg) {
 		cg.addInterface(interfaceName);		
 	}
 	
 	/* (non-Javadoc)
-	 * @see org.eclipse.objectteams.otre.common.ClassEnhancer#addMethod(de.fub.bytecode.classfile.Method, de.fub.bytecode.generic.ClassGen)
+	 * @see org.eclipse.objectteams.otre.common.ClassEnhancer#addMethod(org.apache.bcel.classfile.Method, de.fub.bytecode.generic.ClassGen)
 	 */
 	public void addMethod(Method m, ClassGen cg) {
 		if (cg.containsMethod(m.getName(), m.getSignature()) != null)
@@ -78,7 +78,7 @@
 	}
 	
 	/* (non-Javadoc)
-	 * @see org.eclipse.objectteams.otre.common.ClassEnhancer#addField(de.fub.bytecode.classfile.Field, de.fub.bytecode.generic.ClassGen)
+	 * @see org.eclipse.objectteams.otre.common.ClassEnhancer#addField(org.apache.bcel.classfile.Field, de.fub.bytecode.generic.ClassGen)
 	 */
 	public void addField(Field f, ClassGen cg) {
 		if (cg.containsField(f.getName()) != null)
@@ -109,12 +109,12 @@
 	}
 
 	/* (non-Javadoc)
-	 * @see org.eclipse.objectteams.otre.common.ClassEnhancer#decapsulateMethod(de.fub.bytecode.classfile.Method, java.lang.String, de.fub.bytecode.generic.ConstantPoolGen)
+	 * @see org.eclipse.objectteams.otre.common.ClassEnhancer#decapsulateMethod(org.apache.bcel.classfile.Method, java.lang.String, de.fub.bytecode.generic.ConstantPoolGen)
 	 */
 	public void decapsulateMethod(Method m, ClassGen cg, String packageName, ConstantPoolGen cpg) {
 		String className = cg.getClassName();
 		int flags = m.getAccessFlags();
-		MethodGen mg = new MethodGen(m, className, cpg);
+		MethodGen mg = new MethodGen(m, className, cpg); // no need to remove attributes, code remains unchanged
 
 		if ((flags & Constants.ACC_PUBLIC) == 0) {
 			int newFlags = flags;
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/jplis/ObjectTeamsTransformer.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/jplis/ObjectTeamsTransformer.java
index df7488b..d89a3d9 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/jplis/ObjectTeamsTransformer.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/jplis/ObjectTeamsTransformer.java
@@ -35,6 +35,7 @@
 import org.eclipse.objectteams.otre.LowerableTransformation;
 import org.eclipse.objectteams.otre.OTConstants;
 import org.eclipse.objectteams.otre.ObjectTeamsTransformation;
+import org.eclipse.objectteams.otre.RepositoryAccess;
 import org.eclipse.objectteams.otre.StaticSliceBaseTransformation;
 import org.eclipse.objectteams.otre.SubBoundBaseMethodRedefinition;
 import org.eclipse.objectteams.otre.TeamInterfaceImplementation;
@@ -42,10 +43,10 @@
 import org.eclipse.objectteams.otre.util.AttributeReadingGuard;
 import org.eclipse.objectteams.otre.util.CallinBindingManager;
 
-import de.fub.bytecode.Repository;
-import de.fub.bytecode.classfile.ClassParser;
-import de.fub.bytecode.classfile.JavaClass;
-import de.fub.bytecode.generic.ClassGen;
+import org.apache.bcel.classfile.ClassParser;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.util.ClassLoaderRepository;
 
 
 /**
@@ -112,15 +113,12 @@
 			ProtectionDomain protectionDomain, byte[] classfileBuffer)
 			throws IllegalClassFormatException
 	{
-		if (className.startsWith("org/objectteams/transformer")
-				|| className.startsWith("org/cs3/jmangler")
-				|| className.startsWith("de/fub/bytecode"))
+		if (className.startsWith("org/eclipse/objectteams/otre")
+				|| className.startsWith("org/apache/bcel"))
 		{
-			// skip OTRE, BCEL and JMangler classes
+			// skip OTRE and BCEL classes
 			return null;
 		}
-//		if (!(className.startsWith("java") || className.startsWith("sun")))
-			// System.err.println("ObjectTeamsTransformer transforming: " + className);
 		if (classBeingRedefined != null) {
 			System.out.println("Redefinition!");
 			return null;
@@ -155,8 +153,7 @@
 			= new ThreadActivation();
 				
 		// tell Repository about the class loader for improved lookupClass()
-		ClassLoader prevLoader= Repository.classLoaders.get();
-		Repository.classLoaders.set(loader);
+		ClassLoaderRepository prevRepository = RepositoryAccess.setClassLoader(loader);
 		
 		InputStream is  = new ByteArrayInputStream(classfileBuffer);
 		try {
@@ -219,9 +216,12 @@
 		} catch (IOException e) {
 			System.err.println("ClassFileTransformer could not parse class file buffer to JavaClass");
 			e.printStackTrace();
+		} catch (RuntimeException re) {
+			re.printStackTrace();
+			throw re;
 		} finally {
-			// uninstall class loader:
-			Repository.classLoaders.set(prevLoader);
+			// restore previous repository:
+			RepositoryAccess.resetRepository(prevRepository);
 		}
 		return null;
 	}
@@ -253,13 +253,12 @@
 		ClassParser   cp  = new ClassParser(file, fileName);
 		ClassGen      cg  = new ClassGen(cp.parse());
 		JPLISEnhancer jpe = new JPLISEnhancer(cg, /*loader (unused)*/null);
-		ClassLoader prevLoader= Repository.classLoaders.get();
-		Repository.classLoaders.set(loader);
+		ClassLoaderRepository prevRepository = RepositoryAccess.setClassLoader(loader);
 		try {
 			setFirstTransformation(new ObjectTeamsTransformation(loader, null) {});
 			firstTransformation.checkReadClassAttributes(jpe, cg, cg.getClassName(), cg.getConstantPool());
 		} finally {
-			Repository.classLoaders.set(prevLoader);
+			RepositoryAccess.resetRepository(prevRepository);
 		}
 	}
 	
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/AnnotationHelper.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/AnnotationHelper.java
index 9f01412..0b45daa 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/AnnotationHelper.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/AnnotationHelper.java
@@ -19,9 +19,9 @@
 import org.eclipse.objectteams.otre.ObjectTeamsTransformation;
 import org.objectteams.ImplicitTeamActivation;
 
-import de.fub.bytecode.classfile.Attribute;
-import de.fub.bytecode.classfile.Unknown;
-import de.fub.bytecode.generic.ConstantPoolGen;
+import org.apache.bcel.classfile.Attribute;
+import org.apache.bcel.classfile.Unknown;
+import org.apache.bcel.generic.ConstantPoolGen;
 
 /** 
  * Helper class for parsing / skipping runtime visible annotations.
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/BoundClass.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/BoundClass.java
index 1746be5..63bbb97 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/BoundClass.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/BoundClass.java
@@ -18,7 +18,7 @@
 
 import java.util.HashSet;
 
-import de.fub.bytecode.generic.ObjectType;
+import org.apache.bcel.generic.ObjectType;
 
 /**
  * @version $Id: BoundClass.java,v 1.8 2006-12-19 21:31:30 stephan Exp $ 
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/CallinBindingManager.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/CallinBindingManager.java
index ba2330a..8339cd7 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/CallinBindingManager.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/CallinBindingManager.java
@@ -16,13 +16,13 @@
  **********************************************************************/
 package org.eclipse.objectteams.otre.util;
 
-//import de.fub.bytecode.generic.Type; // just for javadoc.
-import de.fub.bytecode.Repository;
-import de.fub.bytecode.classfile.JavaClass;
-import de.fub.bytecode.generic.ObjectType;
+//import org.apache.bcel.generic.Type; // just for javadoc.
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.generic.ObjectType;
 
 import org.eclipse.objectteams.otre.OTREInternalError;
 import org.eclipse.objectteams.otre.ObjectTeamsTransformation;
+import org.eclipse.objectteams.otre.RepositoryAccess;
 import org.eclipse.objectteams.otre.ObjectTeamsTransformation.BaseMethodInfo;
 
 import java.util.ArrayList;
@@ -78,8 +78,6 @@
 	{
 		BoundClass baseClass = rbb.getBaseClass();
 		ObjectType baseClassType = new ObjectType(baseClassName);
-		if (!checkLookup(baseClassType.getClassName())) // TODO: workaround for classes loaded from special locations
-			return;
 		// clone the set for re-entrance:
 		Iterator<Entry<String, LinkedList<RoleBaseBinding>>> it = getBaseBindingsCloneIterator();
 		while (it.hasNext()) {
@@ -87,11 +85,9 @@
 			String currentBaseClassName = entry.getKey();
 			if (currentBaseClassName.equals(baseClassName)) continue;
 			ObjectType currentType = new ObjectType(currentBaseClassName);
-			if (!checkLookup(currentType.getClassName())) // TODO: workaround for classes loaded from special locations
-				continue;
 			// BoundClass objects are unique per base object, so just take the first binding: 
 			BoundClass currentBaseClass = entry.getValue().getFirst().getBaseClass();
-			if(baseClassType.subclassOf(currentType)) {
+			if(RepositoryAccess.safeSubclassOf(baseClassType, currentType)) {
 				BoundClass rbbSuper = baseClass.getSuper();
 				if (rbbSuper != null)  {
 					if (rbbSuper.getName().equals(currentBaseClassName))
@@ -100,7 +96,7 @@
 				}
 				baseClass.setSuper(currentBaseClass);
 			}
-			else if (currentType.subclassOf(baseClassType)) {
+			else if (RepositoryAccess.safeSubclassOf(currentType, baseClassType)) {
 				BoundClass currentSuper = currentBaseClass.getSuper();
 				// if sub base classes may be registered before super base class, 
 				// this case has to be considered too:
@@ -138,8 +134,14 @@
      * @param baseClassName
      */
     public static void addTeamBaseRelation(String teamClassName, String baseClassName) {
-    	JavaClass baseClass = Repository.lookupClass(baseClassName);
-    	if (checkLookup(baseClassName) && baseClass.isInterface()) { // TODO: workaround for classes loaded from special locations
+    	JavaClass baseClass = null;
+		try {
+			baseClass = RepositoryAccess.lookupClass(baseClassName);
+		} catch (ClassNotFoundException e) {
+			// FIXME(SH): where to log?
+			e.printStackTrace();
+		}
+    	if (baseClass != null && baseClass.isInterface()) { 
     		// TODO (SH): need to register with all implementing classes!
             if (logging) {
                 ObjectTeamsTransformation.printLogMessage("*** Skipping base " + baseClassName + ": is an interface");
@@ -226,7 +228,7 @@
 	 * @param bindingLineOffset TODO
 	 * @param roleMethodName
 	 * @param roleMethodSignature signature ready for interpretation by
-     *                      {@link Type de.fub.bytecode.generic.Type}
+     *                      {@link Type org.apache.bcel.generic.Type}
 	 * @param isStaticRoleMethod TODO
 	 * @param modifier "before", "after" or "replace"
 	 * @param baseMethodName
@@ -400,8 +402,6 @@
 
 		List<MethodBinding> result = new LinkedList<MethodBinding>();
 		ObjectType current = new ObjectType(className);
-		if (!checkLookup(current.getClassName())) // TODO: workaround for classes loaded from special locations
-			return result; 
 		// clone for re-entrance:
 		Iterator<Entry<String, LinkedList<RoleBaseBinding>>> it= getBaseBindingsCloneIterator();
 		while (it.hasNext()) {
@@ -410,11 +410,7 @@
 			// look for true superClass (not same):
 			if (have.equals(className)) continue;
 			ObjectType haveType = new ObjectType(have);
-			//System.err.println(current + " : "+haveType);
-			//System.err.println(de.fub.bytecode.Repository.lookupClass(have));
-			if (!checkLookup(haveType.getClassName())) // TODO: workaround for classes loaded from special locations
-					continue;
-			if (current.subclassOf(haveType)) {
+			if (RepositoryAccess.safeSubclassOf(current, haveType)) {
 				// now we have a true superClass:
 				if (logging)
                     ObjectTeamsTransformation.printLogMessage(className
@@ -448,8 +444,6 @@
 	{
 		List<String> result = new LinkedList<String>();
 		ObjectType current = new ObjectType(className);
-		if (!checkLookup(current.getClassName())) // TODO: workaround for classes loaded from special locations
-			return result; 
 		// clone for re-entrance:
 		Iterator<Entry<String, LinkedList<RoleBaseBinding>>> it = getBaseBindingsCloneIterator();
 		boolean getNextClass = false;
@@ -459,9 +453,7 @@
 			// look for true superClass (not same):
 			if (have.equals(className)) continue;
 			ObjectType haveType = new ObjectType(have);
-			if (!checkLookup(haveType.getClassName())) // TODO: workaround for classes loaded from special locations
-					continue;
-			if (current.subclassOf(haveType)) {
+			if (RepositoryAccess.safeSubclassOf(current, haveType)) {
 				// now we have a true superClass:
 				if (logging)
 					ObjectTeamsTransformation.printLogMessage(className
@@ -515,11 +507,9 @@
 		String subTeamName = subType.substring(0, dollarIdxSub);
 		String superTeamName = superType.substring(0,dollarIdxSuper);
 
-		if (!(checkLookup(subTeamName) && checkLookup(superTeamName)))
-				return false; // Repository can not lookup types
 		ObjectType subTeamType = new ObjectType(subTeamName);
 		ObjectType superTeamType = new ObjectType(superTeamName);
-		if (subTeamType.subclassOf(superTeamType)) {
+		if (RepositoryAccess.safeSubclassOf(subTeamType, superTeamType)) {
             if (logging)
                 ObjectTeamsTransformation.printLogMessage(subType
                         + " implicitly inherits method bindings from " + superType);
@@ -530,22 +520,6 @@
 	}
 	
 	/**
-	 * Check to avoid NullPointerExceptions caused by the Repository when classes can not be looked up (because they loaded by
-	 * classloaders with special a classpath)
-	 *
-	 * @param current	The name of the class to look up in the Repository.
-	 * @return False, if the class can not be found, true else.
-	 */
-	private static boolean checkLookup(String className) {
-		if (Repository.lookupClass(className) == null) {
-			if (OTEQUINOX_WARN)
-				System.err.println("Warning: Repository could not lookup class " + className + "!");
-			return false;
-		}
-		return true;
-	}
-
-	/**
 	 * Get all inherited method bindings for a given base method, which are 
 	 * bindings declared for a super base class.
 	 *
@@ -772,7 +746,7 @@
 //			if (have.equals(baseClassName)) continue;
 //			ObjectType haveType = new ObjectType(have);
 //			//System.err.println(current + " : "+haveType);
-//			//System.err.println(de.fub.bytecode.Repository.lookupClass(have));
+//			//System.err.println(org.apache.bcel.Repository.lookupClass(have));
 //			if (!checkLookup(haveType.getClassName())) // TODO: workaround for classes loaded from special locations
 //					continue;
 //			if (current.subclassOf(haveType)) {
@@ -924,11 +898,15 @@
 	
 	private static List<String> getSuperTeamsWithParamMappigs(String teamName) {
 		LinkedList<String> result = new LinkedList<String>();
-		if (!checkLookup(teamName)) // TODO: workaround for classes loaded from special locations
-			return result;
-		for (JavaClass superTeam : Repository.getSuperClasses(teamName))
-			if (paramMappings.get(superTeam.getClassName()) != null)
-				result.add(superTeam.getClassName());
+		try {
+			for (JavaClass superTeam : RepositoryAccess.getSuperClasses(teamName))
+				if (paramMappings.get(superTeam.getClassName()) != null)
+					result.add(superTeam.getClassName());
+		} catch (ClassNotFoundException e) {
+			// FIXME(SH): where to log to?
+			e.printStackTrace();
+			// continue, just nothing added to result
+		}
 		return result;
 	}
 	
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/DebugUtil.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/DebugUtil.java
index 7282185..c6e8d80 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/DebugUtil.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/DebugUtil.java
@@ -16,9 +16,9 @@
  **********************************************************************/
 package org.eclipse.objectteams.otre.util;
 
-import de.fub.bytecode.generic.*;
-import de.fub.bytecode.Constants;
-import java.util.Enumeration;
+import org.apache.bcel.generic.*;
+import org.apache.bcel.Constants;
+import java.util.Iterator;
 
 import org.eclipse.objectteams.otre.OTConstants;
 
@@ -142,9 +142,9 @@
     @SuppressWarnings("unchecked")
 	public static void printIL (InstructionList il, ConstantPoolGen cpg) {
         int off = 0;
-        Enumeration en =  il.elements();
-        while(en.hasMoreElements()) {
-            Instruction i = ((InstructionHandle)en.nextElement()).getInstruction();
+        Iterator<InstructionHandle> it =  il.iterator();
+        while(it.hasNext()) {
+            Instruction i = it.next().getInstruction();
             off += i.produceStack(cpg);
             off -= i.consumeStack(cpg);
             System.out.print(off);
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/ListValueHashMap.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/ListValueHashMap.java
index 665ee5f..8b7b463 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/ListValueHashMap.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/ListValueHashMap.java
@@ -84,9 +84,9 @@
 	
 	public String toString() {
 		StringBuilder result = new StringBuilder(32);
-		Iterator it = hashMap.entrySet().iterator();
+		Iterator<Entry<String,LinkedList<ValueType>>> it = hashMap.entrySet().iterator();
 		while (it.hasNext()) {
-			Entry entry = (Entry) it.next();
+			Entry<String,LinkedList<ValueType>> entry = it.next();
 			result.append(entry.getKey());
             result.append(": ");
             result.append(entry.getValue().toString());
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/RoleBaseBinding.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/RoleBaseBinding.java
index 172c0ae..2a8c30b 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/RoleBaseBinding.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/util/RoleBaseBinding.java
@@ -212,10 +212,10 @@
         out.append(" <-> ");
         out.append(baseClass.getName());
 	    out.append("\nmethod bindings:\n");
-	    List mbsList = getBaseMethodBindings();
-	    Iterator it = mbsList.iterator();
+	    List<MethodBinding> mbsList = getBaseMethodBindings();
+	    Iterator<MethodBinding> it = mbsList.iterator();
 	    while (it.hasNext()) {
-			MethodBinding mb = (MethodBinding)it.next();
+			MethodBinding mb = it.next();
 			out.append("\n");
             out.append(mb.getBaseMethodName());
             out.append(".");
diff --git a/othersrc/OTRE/src/org/objectteams/DoublyWeakHashMap.java b/othersrc/OTRE/src/org/objectteams/DoublyWeakHashMap.java
index 4b72f1e..bbf4ef8 100644
--- a/othersrc/OTRE/src/org/objectteams/DoublyWeakHashMap.java
+++ b/othersrc/OTRE/src/org/objectteams/DoublyWeakHashMap.java
@@ -30,8 +30,8 @@
  * 
  * @author stephan
  * @since 0.7.0
- * @param <K>
- * @param <V>
+ * @param <K> type of keys: a base class
+ * @param <V> type of values: a role class
  */
 public class DoublyWeakHashMap<K,V> implements Map<K,V> {
 
@@ -40,6 +40,7 @@
 	public DoublyWeakHashMap() {
 		this.map = new WeakHashMap<K, WeakReference<V>>();
 	}
+	
 	public int size() {
 		return this.map.size();
 	}
@@ -48,23 +49,28 @@
 		return this.map.isEmpty();
 	}
 
+	// used from hasRole() and lifting (duplicate role check)
 	public boolean containsKey(Object key) {
 		return this.map.containsKey(key);
 	}
 
 	public boolean containsValue(Object value) {
-		return this.map.containsValue(value);
+		throw new UnsupportedFeatureException("Method containsValue is not implemented for internal class DoublyWeakHashMap.");
 	}
 
+	// used from getRole()
 	public V get(Object key) {
-		return this.map.get(key).get();
+		WeakReference<V> valRef = this.map.get(key);
+		return valRef == null ? null : valRef.get();
 	}
 
+	// used from migrateToBase() and lifting constructor
 	public V put(K key, V value) {
 		this.map.put(key, new WeakReference<V>(value));
 		return value;
 	}
 
+	// used from unregisterRole(), migrateToBase()
 	public V remove(Object key) {
 		WeakReference<V> value = this.map.remove(key);
 		return (value == null) ? null : value.get();
@@ -83,14 +89,18 @@
 		return this.map.keySet();
 	}
 
+	// used from getAllRoles() et al.
 	public Collection<V> values() {
 		ArrayList<V> result = new ArrayList<V>(this.map.size());
-		for (WeakReference<V> valRef : this.map.values())
-			result.add(valRef.get());
+		for (WeakReference<V> valRef : this.map.values()) {
+			V value = valRef.get();
+			if (value != null)
+				result.add(value);
+		}
 		return result;
 	}
 
 	public Set<java.util.Map.Entry<K, V>> entrySet() {
-		throw new UnsupportedFeatureException("Method entrySet is not implemented for DoublyWeakHashMap");
+		throw new UnsupportedFeatureException("Method entrySet is not implemented for internal class DoublyWeakHashMap.");
 	}
 }
diff --git a/othersrc/OTRE/src/org/objectteams/WrongRoleException.java b/othersrc/OTRE/src/org/objectteams/WrongRoleException.java
index da84d33..ed76541 100644
--- a/othersrc/OTRE/src/org/objectteams/WrongRoleException.java
+++ b/othersrc/OTRE/src/org/objectteams/WrongRoleException.java
@@ -27,7 +27,7 @@
 	 * 
 	 */
 	private static final long serialVersionUID = 1L;
-	private Class clazz;
+	private Class<?> clazz;
 	private Object base;
 	private Object role;
 
@@ -36,7 +36,7 @@
 	 * @param base
 	 * @param role
 	 */
-	public WrongRoleException (Class clazz, Object base, Object role) {
+	public WrongRoleException (Class<?> clazz, Object base, Object role) {
 		this.clazz = clazz;
 		this.base = base;
 		this.role = role;