Bug 433080 - [otdre] encode weaving scheme in class files
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index b4e7a4a..7519a31 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -2263,8 +2263,11 @@
 	int RoleFileMissingTeamDeclaration			 = LIMITATIONS + 	 32;
 	
 	/** @since 3.10 OT 2.3 */
-	int OtreCannotWeaveIntoJava8					 = LIMITATIONS + 33;
+	int OtreCannotWeaveIntoJava8				 = LIMITATIONS + 	 33;
 	
+	/** @since 3.10 OT 2.3 */
+	int IncompatibleWeavingScheme				 = LIMITATIONS + 	 34;
+
 // ==== EXPERIMENTAL: ====
 	int EXPERIMENTAL = OTJ_RELATED + 12*OTCHAP;
 	int MigrateNonRole 							 = EXPERIMENTAL +     1;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index 72995c4..070608d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -149,9 +149,11 @@
 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
 import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme;
 import org.eclipse.jdt.internal.compiler.impl.IrritantSet;
 import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
 import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
+import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding;
 import org.eclipse.jdt.internal.compiler.lookup.Binding;
 import org.eclipse.jdt.internal.compiler.lookup.CaptureBinding;
 import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
@@ -13545,6 +13547,14 @@
 			argument,
 			0, 0);
 }
+public void incompatibleWeavingScheme(BinaryTypeBinding type, WeavingScheme scheme) {
+	String[] argument = new String[] { new String(type.getFileName()), scheme.name() };
+	this.handle(
+			IProblem.IncompatibleWeavingScheme,
+			argument,
+			argument,
+			0, 0);
+}
 public void callinBindingToInterface(AbstractMethodMappingDeclaration callinMapping, ReferenceBinding baseIfc) {
 	String[] args = { String.valueOf(baseIfc.readableName()) };
 	this.handle(IProblem.CallinBindingToInterface, args, args, callinMapping.sourceStart, callinMapping.sourceEnd);	
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index d783526..f77d528 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -1243,6 +1243,7 @@
 2100031 = Corrupt byte code: attempt to invoke abstract method {0}.
 2100032 = Role file {0} lacks a team package declaration, is this file on its project's classpath? 
 2100033 = Base class {0} has class file version {1} which cannot be handled by the traditional OTRE based on BCEL. Please consider using the ASM based OTDRE instead.
+2100034 = Class file {0} has been compiled for incompatible weaving target '{1}', please consider a full build of the declaring project.
 
 ## EXPERIMENTAL
 2200001 = Type {0} does not support team migration, only applicable for roles (OT/J experimental feature).
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/IOTConstants.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/IOTConstants.java
index b8e64df..065e523 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/IOTConstants.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/IOTConstants.java
@@ -34,7 +34,7 @@
 	public final static class OTVersion {
 		// methods, not constants, so these won't get inlined in any byte code.
 		public static final int  getMajor() { return 1; }
-		public static final int  getMinor() { return 6; }
+		public static final int  getMinor() { return 7; }
 		public static final int  getRevsion() { return 0; }
 		public static final int  getCompilerVersionMin() { return (1<<9)+(4<<5)+1; }// byte code incompatibility introduced in internal version 1.4.1 (OTDT 1.4.0M3)
 	}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/WordValueAttribute.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/WordValueAttribute.java
index ec0b455..d0baf94 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/WordValueAttribute.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/WordValueAttribute.java
@@ -1,7 +1,7 @@
 /**********************************************************************
  * This file is part of "Object Teams Development Tooling"-Software
  *
- * Copyright 2004, 2006 Fraunhofer Gesellschaft, Munich, Germany,
+ * Copyright 2004, 2014 Fraunhofer Gesellschaft, Munich, Germany,
  * for its Fraunhofer Institute for Computer Architecture and Software
  * Technology (FIRST), Berlin, Germany and Technical University Berlin,
  * Germany.
@@ -10,7 +10,6 @@
  * 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: WordValueAttribute.java 23416 2010-02-03 19:59:31Z stephan $
  *
  * Please visit http://www.eclipse.org/objectteams for updates and contact.
  *
@@ -28,6 +27,7 @@
 import org.eclipse.jdt.internal.compiler.classfmt.FieldInfo;
 import org.eclipse.jdt.internal.compiler.classfmt.MethodInfo;
 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme;
 import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding;
 import org.eclipse.jdt.internal.compiler.lookup.Binding;
 import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
@@ -40,6 +40,7 @@
 import org.eclipse.objectteams.otdt.core.exceptions.InternalCompilerError;
 import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel;
 import org.eclipse.objectteams.otdt.internal.core.compiler.model.TypeModel;
+import org.eclipse.objectteams.otdt.internal.core.compiler.util.TSuperHelper;
 import org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer;
 
 
@@ -98,13 +99,14 @@
  *
  * </ul>
  * @author stephan
- * @version $Id: WordValueAttribute.java 23416 2010-02-03 19:59:31Z stephan $
  */
 public class WordValueAttribute
         extends AbstractAttribute
 {
     // ============== STATIC API ===================
 
+	private static final int OTDRE_FLAG = 1 << 15;
+
 	public static void maybeCreateClassFlagsAttribute(TypeDeclaration type) {
 		TypeModel model = null;
 		int classFlags = 0;
@@ -252,6 +254,16 @@
 				+ (OTVersion.getRevsion()));
     }
 
+	public void setWeavingScheme(WeavingScheme weavingScheme) {
+		switch (weavingScheme) {
+			case OTRE:
+				break; // is the default
+			case OTDRE: 
+				this._value |= OTDRE_FLAG;
+				break;
+		}
+	}
+
     // ============== INSTANCE FEATURES ===================
 
 
@@ -350,6 +362,22 @@
         		type.getTeamModel()._compilerVersion = this._value;
         	if (this._value < IOTConstants.OTVersion.getCompilerVersionMin())
         		environment.problemReporter.incompatibleOTJByteCodeVersion(((BinaryTypeBinding)binding).getFileName(), getBytecodeVersionString(this._value));
+        	if ((type.isRole() || type.isTeam())
+        			&& !CharOperation.equals(type.getPackage().compoundName, IOTConstants.ORG_OBJECTTEAMS)
+        			&& !TypeAnalyzer.isPredefinedRole(type)
+        			&& !TSuperHelper.isMarkerInterface(type))
+        	{
+				switch (environment.globalOptions.weavingScheme) {
+	        		case OTRE: 
+	        			if ((this._value & OTDRE_FLAG) != 0)
+	        				environment.problemReporter.incompatibleWeavingScheme(type, WeavingScheme.OTDRE);
+	        			break;
+	        		case OTDRE: 
+	        			if ((this._value & OTDRE_FLAG) == 0)
+	        				environment.problemReporter.incompatibleWeavingScheme(type, WeavingScheme.OTRE);
+	        			break;
+	        	}
+			}
         }
     }
 
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
index e54da30..3ba65d3 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
@@ -1996,6 +1996,7 @@
 	{
         boolean success = true;
         TypeDeclaration roleDecl = role.getAst();
+        WeavingScheme weavingScheme = role.getWeavingScheme(); // always trigger initialization
 		if (Config.getConfig().verifyMethods)
         { 
 			if (roleDecl == null) {
@@ -2012,7 +2013,7 @@
 	        	if (!roleDecl.binding.isSynthInterface()) {
 	        		// synth interfaces have no callins anyway ;-)
 		            if (needMethodBodies) {  // not translating callin bindings will cause no secondary errors -> skip if no body needed
-		            	switch (roleDecl.scope.compilerOptions().weavingScheme) {
+						switch (weavingScheme) {
 		            	case OTDRE:
 		            		CallinImplementorDyn callinImplementorDyn = new CallinImplementorDyn();
 		            		callinImplementorDyn.transformRole(role);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TypeModel.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TypeModel.java
index c443172..2d7c0bc 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TypeModel.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TypeModel.java
@@ -1,7 +1,7 @@
 /**********************************************************************
  * This file is part of "Object Teams Development Tooling"-Software
  *
- * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
+ * Copyright 2004, 2014 Fraunhofer Gesellschaft, Munich, Germany,
  * for its Fraunhofer Institute for Computer Architecture and Software
  * Technology (FIRST), Berlin, Germany and Technical University Berlin,
  * Germany.
@@ -49,6 +49,7 @@
 import org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.OTSpecialAccessAttribute;
 import org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ReferencedTeamsAttribute;
 import org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.RoleFilesAttribute;
+import org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.WordValueAttribute;
 import org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies;
 import org.eclipse.objectteams.otdt.internal.core.compiler.control.ITranslationStates;
 import org.eclipse.objectteams.otdt.internal.core.compiler.control.StateMemento;
@@ -564,8 +565,17 @@
 		return false;
 	}
 	public WeavingScheme getWeavingScheme() {
-		if (this.weavingScheme == null && this._ast != null && this._ast.scope != null)
+		if (this.weavingScheme == null && this._ast != null && this._ast.scope != null) {
 			this.weavingScheme = this._ast.scope.compilerOptions().weavingScheme;
+			if (this.weavingScheme == WeavingScheme.OTDRE) {
+				if (this._attributes != null)
+					for (int i = 0; i < this._attributes.length; i++)
+						if (this._attributes[i].nameEquals(IOTConstants.OT_COMPILER_VERSION)) {
+							((WordValueAttribute)this._attributes[i]).setWeavingScheme(this.weavingScheme);
+							break;
+						}
+			}
+		}
 		return this.weavingScheme;
 	}
 }
diff --git a/plugins/org.eclipse.objectteams.otre/src/org/eclipse/objectteams/otre/OTConstants.java b/plugins/org.eclipse.objectteams.otre/src/org/eclipse/objectteams/otre/OTConstants.java
index 6f9653f..48ead63 100644
--- a/plugins/org.eclipse.objectteams.otre/src/org/eclipse/objectteams/otre/OTConstants.java
+++ b/plugins/org.eclipse.objectteams.otre/src/org/eclipse/objectteams/otre/OTConstants.java
@@ -99,6 +99,9 @@
     // required compiler revision in the 1.6 (=0.8/2.0) stream:
     public static final int    OT16_REVISION = 0;
 
+    // required compiler revision in the 1.7 (=2.3) stream:
+    public static final int    OT17_REVISION = 0;
+
     // ------------------------------------------
 	// ---------- Flags and Modifiers: ----------
 	// ------------------------------------------
diff --git a/plugins/org.eclipse.objectteams.otre/src/org/eclipse/objectteams/otre/ObjectTeamsTransformation.java b/plugins/org.eclipse.objectteams.otre/src/org/eclipse/objectteams/otre/ObjectTeamsTransformation.java
index a43c0bb..c3370e0 100644
--- a/plugins/org.eclipse.objectteams.otre/src/org/eclipse/objectteams/otre/ObjectTeamsTransformation.java
+++ b/plugins/org.eclipse.objectteams.otre/src/org/eclipse/objectteams/otre/ObjectTeamsTransformation.java
@@ -1,7 +1,7 @@
 /**********************************************************************
  * This file is part of the "Object Teams Runtime Environment"
  * 
- * Copyright 2002-2009 Berlin Institute of Technology, Germany.
+ * Copyright 2002-2014 Berlin Institute of Technology, Germany.
  * 
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -1087,8 +1087,17 @@
                     if(logging) printLogMessage("**** class file was produced by compiler version "
                             + major + "." + minor + "." + revision + " ****");
                     IS_COMPILER_GREATER_123 = false; // reset, may be updated below
+                    // OTDRE?
+                    if ((encodedVersion & 0x8000) != 0)
+                    	throw new UnsupportedClassVersionError("OTRE: Class "+class_name+" was compiled for incompatible weaving target OTDRE");
+					// 1.7 stream:
+					if (major == 1 && minor == 7) {
+						// accept all revisions within this stream
+						IS_COMPILER_GREATER_123 = true;
+						IS_COMPILER_13X_PLUS = true;
+						IS_COMPILER_14X_PLUS = true;
 					// 1.6 stream:
-					if (major == 1 && minor == 6) {
+					} else if (major == 1 && minor == 6) {
 						// accept all revisions within this stream
 						IS_COMPILER_GREATER_123 = true;
 						IS_COMPILER_13X_PLUS = true;
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/Attributes.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/Attributes.java
index 95f8f68..35ea8bb 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/Attributes.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/Attributes.java
@@ -38,13 +38,30 @@
 	protected final static String ATTRIBUTE_CALLIN_PRECEDENCE = "CallinPrecedence";

 	protected final static String ATTRIBUTE_OT_CLASS_FLAGS = "OTClassFlags";

 	protected final static String ATTRIBUTE_OT_SPECIAL_ACCESS = "OTSpecialAccess";

+	protected final static String ATTRIBUTE_OT_COMPILER_VERSION = "OTCompilerVersion";

+	

+	private static final int OTDRE_FLAG = 0x8000; // high bit in OTCompilerVersion

 

 	protected final static Attribute[] attributes = { 

 		new CallinBindingsAttribute(0),

 		new CallinPrecedenceAttribute(0),

 		new OTClassFlagsAttribute(0),

-		new OTSpecialAccessAttribute()

+		new OTSpecialAccessAttribute(),

+		new OTCompilerVersion(0)

 	};

+	protected static class OTCompilerVersion extends Attribute {

+

+		protected OTCompilerVersion(int version) {

+			super(ATTRIBUTE_OT_COMPILER_VERSION);

+		}

+		@Override

+		protected Attribute read(ClassReader cr, int off, int len, char[] buf, int codeOff, Label[] labels) {

+			int encodedVersion  = cr.readUnsignedShort(off);

+			if ((encodedVersion & OTDRE_FLAG) == 0)

+            	throw new UnsupportedClassVersionError("OTDRE: Class "+cr.getClassName()+" was compiled for incompatible weaving target OTRE");

+			return new OTCompilerVersion(encodedVersion);

+		}

+	}

 	

 	protected static class CallinBindingsAttribute extends Attribute {

 		static final short COVARIANT_BASE_RETURN = 8;

diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/callinbinding/BaseCalls.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/callinbinding/BaseCalls.java
index c983ef8..4291a8b 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/callinbinding/BaseCalls.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/callinbinding/BaseCalls.java
@@ -24,6 +24,7 @@
 
 import org.eclipse.jdt.core.tests.util.Util;
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.objectteams.otdt.core.ext.WeavingScheme;
 import org.eclipse.objectteams.otdt.tests.otjld.AbstractOTJLDTest;
 
 @SuppressWarnings("unchecked") // working with raw map
@@ -2001,6 +2002,8 @@
 			    "}\n" +
 			    "    \n"
             },
+            (this.weavingScheme == WeavingScheme.OTRE
+            ?
             "----------\n" + 
     		"1. ERROR in T4513bsa3Main.java (at line 1)\n" + 
     		"	\n" + 
@@ -2013,7 +2016,22 @@
     		"public class T4513bsa3Main {\n" + 
     		"	^\n" + 
     		"Class file Team4513bsa3$__OT__Confined.class has incompatible OT/J byte code version 1.2.3, please consider a full build of the declaring project.\n" + 
-    		"----------\n",
+    		"----------\n"
+    		:
+            "----------\n" + 
+    		"1. ERROR in T4513bsa3Main.java (at line 1)\n" + 
+    		"	\n" + 
+    		"public class T4513bsa3Main {\n" + 
+    		"	^\n" + 
+    		"Class file Team4513bsa3$__OT__R.class has incompatible OT/J byte code version 1.2.3, please consider a full build of the declaring project.\n" + 
+    		"----------\n" + 
+    		"2. ERROR in T4513bsa3Main.java (at line 0)\n" + 
+    		"	\n" + 
+    		"public class T4513bsa3Main {\n" + 
+    		"	^\n" + 
+    		"Class file Team4513bsa3$__OT__R.class has been compiled for incompatible weaving target 'OTRE', please consider a full build of the declaring project.\n" + 
+    		"----------\n"
+    		),
             classPaths,
             false/*shouldFlushOutputDirectory*/);
     }
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Misc.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Misc.java
index ee539de..73bd3f2 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Misc.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Misc.java
@@ -20,8 +20,10 @@
 
 import junit.framework.Test;
 
+import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.tests.util.Util;
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.objectteams.otdt.core.ext.WeavingScheme;
 import org.eclipse.objectteams.otdt.tests.otjld.AbstractOTJLDTest;
 
 @SuppressWarnings("unchecked")
@@ -34,7 +36,7 @@
      // Static initializer to specify tests subset using TESTS_* static variables
      // All specified tests which does not belong to the class are skipped...
      static {
-//        TESTS_NAMES = new String[] { "test04m_javadocBaseImportReference1"};
+//        TESTS_NAMES = new String[] { "testMixedClassFileFormats3"};
 //        TESTS_NUMBERS = new int { 1459 };
 //        TESTS_RANGE = new int { 1097, -1 };
      }
@@ -504,6 +506,121 @@
             null/*vmArguments*/);
      }
      
+     // reading a base class compiled with a different weaving scheme is *no* problem
+     public void testMixedClassFileFormats2() {
+    	 WeavingScheme scheme = this.weavingScheme;
+    	 try {
+	    	 Map options = getCompilerOptions();
+	    	 options.put(JavaCore.COMPILER_OPT_WEAVING_SCHEME, WeavingScheme.OTRE.name());
+	    	 this.weavingScheme = WeavingScheme.OTRE;
+	    	 runConformTest(
+	    		new String[] {
+	    			"mcff2/Base.java",
+	    			"package mcff2;\n" +
+	    			"public class Base {" +
+	    			"	public static void main(String[] args) {}\n" +
+	    			"}\n"
+	    		}, 
+	    		"", null, false, new String[] {"-Dotre2"}, options, null); // force starting a new vm
+	    	 options.put(JavaCore.COMPILER_OPT_WEAVING_SCHEME, WeavingScheme.OTDRE.name());
+	    	 this.weavingScheme = WeavingScheme.OTDRE;
+	    	 runConformTest(
+	    		new String[] {
+	    			"mcff2/Team1.java",
+	    			"package mcff2;\n" +
+	    			"public team class Team1 {\n" +
+	    			"	protected class R playedBy Base {\n" +
+	    			"	}\n" +
+	    			"	public static void main(String[] args) {}\n" +
+	    			"}\n"
+	    		}, 
+	    		"", null, false, new String[] {"-Dotdre2"}, options, null);
+    	 } finally {
+    		 this.weavingScheme = scheme;
+    	 }
+     }
+     
+     // reading a team class compiled with a different weaving scheme *is* a problem
+     public void testMixedClassFileFormats3() {
+    	 WeavingScheme scheme = this.weavingScheme;
+    	 try {
+	    	 Map options = getCompilerOptions();
+	    	 options.put(JavaCore.COMPILER_OPT_WEAVING_SCHEME, WeavingScheme.OTRE.name());
+	    	 this.weavingScheme = WeavingScheme.OTRE;
+	    	 runConformTest(
+	    		new String[] {
+	    			"mcff3/Team1.java",
+	    			"package mcff3;\n" +
+	    			"public team class Team1 {\n" +
+	    			"	public static void main(String[] args) {}\n" +
+	    			"}\n"
+	    		}, 
+	    		"", null, false, new String[] {"-Dotre3"}, options, null);
+	    	 options.put(JavaCore.COMPILER_OPT_WEAVING_SCHEME, WeavingScheme.OTDRE.name());
+	    	 this.weavingScheme = WeavingScheme.OTDRE;
+	    	 runNegativeTest(
+	    		new String[] {
+	    			"mcff3/Team2.java",
+	    			"package mcff3;\n" +
+	    			"public team class Team2 extends Team1 {\n" +
+	    			"	protected class R {\n" +
+	    			"	}\n" +
+	    			"}\n"
+	    		},
+	    		"----------\n" + 
+				"1. ERROR in mcff3\\Team2.java (at line 1)\n" + 
+				"	package mcff3;\n" + 
+				"	^\n" + 
+				"Class file "+OUTPUT_DIR+"/mcff3/Team1.class has been compiled for incompatible weaving target \'OTRE\', please consider a full build of the declaring project.\n" + 
+				"----------\n",
+				null,
+	    		false,
+	    		options);
+    	 } finally {
+    		 this.weavingScheme = scheme;
+    	 }
+     }
+
+     // reading a team class compiled with a different weaving scheme *is* a problem - opposite direction
+     public void testMixedClassFileFormats4() {
+    	 WeavingScheme scheme = this.weavingScheme;
+    	 try {
+    		 Map options = getCompilerOptions();
+	    	 options.put(JavaCore.COMPILER_OPT_WEAVING_SCHEME, WeavingScheme.OTDRE.name());
+	    	 this.weavingScheme = WeavingScheme.OTDRE;
+	    	 runConformTest(
+	    		new String[] {
+	    			"mcff4/Team1.java",
+	    			"package mcff4;\n" +
+	    			"public team class Team1 {\n" +
+	    			"	public static void main(String[] args) {}\n" +
+	    			"}\n"
+	    		}, 
+	    		"", null, false, new String[] {"-Dotdre4"}, options, null);
+	    	 options.put(JavaCore.COMPILER_OPT_WEAVING_SCHEME, WeavingScheme.OTRE.name());
+	    	 this.weavingScheme = WeavingScheme.OTRE;
+	    	 runNegativeTest(
+	    		new String[] {
+	    			"mcff4/Team2.java",
+	    			"package mcff4;\n" +
+	    			"public team class Team2 extends Team1 {\n" +
+	    			"	protected class R {}\n" +
+	    			"}\n"
+	    		},
+	    		"----------\n" + 
+				"1. ERROR in mcff4\\Team2.java (at line 1)\n" + 
+				"	package mcff4;\n" + 
+				"	^\n" + 
+				"Class file "+OUTPUT_DIR+"/mcff4/Team1.class has been compiled for incompatible weaving target \'OTDRE\', please consider a full build of the declaring project.\n" + 
+				"----------\n",
+				null,
+	    		false,
+	    		options);
+    	 } finally {
+    		 this.weavingScheme = scheme;
+    	 }
+     }
+
      // Bug 304728 - [otre] [compiler] Support basic serialization of teams and roles
      // Bug 304729 - [otre] Selectively consider activation state during team serialization
      public void _testTeamSerialization1() {
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/ReportedBugs.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/ReportedBugs.java
index 218f2ca..c57ce45 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/ReportedBugs.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/ReportedBugs.java
@@ -5317,7 +5317,8 @@
             "Adaptation");
     }
     public void testBug372786() {
-    	runNegativeTest(
+    	String jarFilename = this.weavingScheme == WeavingScheme.OTRE ? "bug372786.jar" : "bug372786otdre.jar";
+		runNegativeTest(
     		new String[] {
     	"TBug372786.java",
     			"import jarred.TeamBug372786;\n" +
@@ -5334,7 +5335,7 @@
     		"	^\n" + 
     		"The type notjarred.Missing cannot be resolved. It is indirectly referenced from required .class files\n" + 
     		"----------\n",
-    		getClassLibraries("bug372786.jar"),
+    		getClassLibraries(jarFilename),
     		false);
     }
 
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/testresources/bug372786otdre.jar b/testplugins/org.eclipse.objectteams.otdt.tests/testresources/bug372786otdre.jar
new file mode 100644
index 0000000..d5df4e6
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/testresources/bug372786otdre.jar
Binary files differ