Various fixes for Bug 372786 - NPE in AllocationExpression
.resolveAsRoleCreationExpression when working with OTDT source bundle
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java
index c0e16b8..187978d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java
@@ -148,8 +148,10 @@
 		    {
 		    	TypeAnchorReference typeAnchorReference = (TypeAnchorReference)this.typeArguments[typeParamPos];
 				ITeamAnchor anchor = typeAnchorReference.resolveAnchor(scope);
-				if (!ProblemAnchorBinding.checkAnchor(scope, typeAnchorReference, anchor, this.token))
-					return null;
+				if (!ProblemAnchorBinding.checkAnchor(scope, typeAnchorReference, anchor, this.token)) {
+					int problemId = anchor != null ? anchor.problemId() : ProblemReasons.AnchorNotFound;
+					return this.resolvedType = new ProblemReferenceBinding(anchor, typeAnchorReference.getLastToken(), null, problemId);
+				}
 		    	for (ITeamAnchor seg : anchor.getBestNamePath())
 		    		if (!seg.isFinal())
 		    			scope.problemReporter().anchorPathNotFinal(typeAnchorReference, seg, this.token);
@@ -169,17 +171,17 @@
 					this.resolvedType = typeAnchorReference.createDependentTypeBinding(scope, this, typeParamPos);
 					if (this.resolvedType == null) {
 						this.resolvedType = new ProblemReferenceBinding(anchor, this.token, null, ProblemReasons.NotFound);
-						return null;
+						return this.resolvedType;
 					}
 				}
 				if (this.resolvedType != null && this.resolvedType.isValidBinding() && this.resolvedType instanceof ReferenceBinding) {
 					if (!checkParameterizedRoleVisibility(scope, anchor, (ReferenceBinding) this.resolvedType))
-						return null;
+						return this.resolvedType;
 				}
 	
 				if (   shouldAnalyzeRoleReference()
 					&& isIllegalQualifiedUseOfProtectedRole(scope))
-					return null; // problem binding may be in this.resolvedType
+					return this.resolvedType; // problem binding may be in this.resolvedType
 				// consume first arg:
 				int len = 0;
 				if (this.typeAnchors != null) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
index 513f601..cc7ee0a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
@@ -2679,9 +2679,7 @@
 	    if (   (methodBinding == null)
 	        || (methodBinding.declaringClass != this))
 	    {
-			// create it (if successful!)
-	    	if (!methodDeclaration.ignoreFurtherInvestigation)
-	    		this.scope.addGeneratedMethod(methodDeclaration.binding);
+    		this.scope.addGeneratedMethod(methodDeclaration.binding);
 	    }
 	    else
 	    {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/TypeAnchorReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/TypeAnchorReference.java
index c61f923..66b6f7e 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/TypeAnchorReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/TypeAnchorReference.java
@@ -154,6 +154,8 @@
 	public char[] getLastToken() {
 		if (this.anchor instanceof SingleNameReference)
 			return ((SingleNameReference)this.anchor).token;
+		if (this.anchor instanceof QualifiedBaseReference)
+			return IOTConstants.BASE;
 		char[][] tokens = ((QualifiedNameReference)this.anchor).tokens;
 		return tokens[tokens.length-1];
 	}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/StateHelper.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/StateHelper.java
index 0b66019..156f531 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/StateHelper.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/StateHelper.java
@@ -47,6 +47,7 @@
 		switch (state) {
 		case STATE_NONE:
 		case STATE_ROLES_LINKED:
+		case STATE_ROLE_FEATURES_COPIED:
 		case STATE_ROLE_HIERARCHY_ANALYZED:
 		case STATE_FULL_LIFTING:
 		case STATE_FAULT_IN_TYPES:
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java
index 4b40725..d4dbd96 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TeamModel.java
@@ -442,6 +442,8 @@
 	    if (roleType.isParameterizedType())
 	    	roleType = ((ParameterizedTypeBinding)roleType).genericType();
     	ReferenceBinding roleOuter = (ReferenceBinding) roleType.enclosingType().erasure();
+    	if (roleOuter == teamCandidate)
+    		return 1; // shortcut
 	    if (teamCandidate.isRole()) {
 	    	ReferenceBinding outerTeam = teamCandidate.enclosingType();
 	    	int l2 = levelFromEnclosingTeam(outerTeam, roleOuter);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/StandardElementGenerator.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/StandardElementGenerator.java
index bc60037..7bdca62 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/StandardElementGenerator.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/StandardElementGenerator.java
@@ -53,6 +53,7 @@
 import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance;
 import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstEdit;
 import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator;
+import org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator;
 import org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer;
 
 import static org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.*;
@@ -279,6 +280,10 @@
 						new Argument[]{
 							gen.argument(argName, exprTypeRef)
 						});
+		// see org.eclipse.objectteams.otdt.tests.otjld.regression.ReportedBugs.testB11_sh15():
+		// pre-set return type to prevent problems with resolving lateron
+		TypeBinding returnType = dimensions == 0 ? roleType : scope.environment().createArrayType(roleType, dimensions);
+		castMethod.returnType.resolvedType = RoleTypeCreator.maybeWrapUnqualifiedRoleType(returnType, teamBinding);
 
 		// <role> role = (<role>)_OT$arg;
 		TypeReference arrayCastType = gen.createArrayTypeReference(roleType, dimensions);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java
index b671de6..8491934 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java
@@ -844,6 +844,7 @@
 		anonymousType.bodyEnd    = this.sourceEnd;
 		anonymousType.name = CharOperation.NO_CHAR;
 		anonymousType.bits |= (ASTNode.IsAnonymousType|ASTNode.IsLocalType);
+		anonymousType.isGenerated = true;
 		return anonymousType;
 	}
 	
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/api/Reflection.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/api/Reflection.java
index 866f637..9b5c15d 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/api/Reflection.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/api/Reflection.java
@@ -833,6 +833,11 @@
     		"	R<@t> r = t.getRole(o, R<@t>.class);\n" + 
     		"	                       ^\n" + 
     		"Illegal parameterized use of non-public role R (OTJLD 1.2.3(b)).\n" + 
+    		"----------\n" +
+    		"3. ERROR in Team923grm2gp_2.java (at line 8)\n" + 
+    		"	r.print();\n" + 
+    		"	^\n" + 
+    		"The type R is not visible\n" + 
     		"----------\n");
     }
 
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 1501ff2..4b68113 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
@@ -19,6 +19,7 @@
 import java.util.Map;
 
 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.tests.otjld.AbstractOTJLDTest;
 
@@ -39,7 +40,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[] { "testB11_sh9"};
+//		TESTS_NAMES = new String[] { "testBug372786"};
 //		TESTS_NUMBERS = new int[] { 1459 };
 //		TESTS_RANGE = new int[] { 1097, -1 };
 	}
@@ -52,6 +53,20 @@
 		return ReportedBugs.class;
 	}
 
+    
+    String[] getClassLibraries(String jarFilename) {
+    	String destPath = this.outputRootDirectoryPath+"/regression";
+    	createOutputTestDirectory("/regression");
+    	// upload the jar:
+		Util.copy(getTestResourcePath(jarFilename), destPath);
+    	// setup classpath:
+    	String[] classPaths = getDefaultClassPaths();
+    	int l = classPaths.length;
+    	System.arraycopy(classPaths, 0, classPaths=new String[l+1], 0, l);
+		classPaths[l] = this.outputRootDirectoryPath+"/regression/"+jarFilename;
+		return classPaths;
+    }
+
     // reported against GebitProposalComputer - typo in testcase
     // B.1.1-otjld-sh-1f
     public void testB11_sh1f() {
@@ -5218,5 +5233,25 @@
             },
             "Adaptation");
     }
-
+    public void testBug372786() {
+    	runNegativeTest(
+    		new String[] {
+    	"TBug372786.java",
+    			"import jarred.TeamBug372786;\n" +
+    			"public class TBug372786 {\n" +
+    			"	TeamBug372786 t;\n" +
+    			"   void test() {\n" +
+    			"       t.run();\n" +
+    			"   }\n" +
+    			"}\n"
+    		},
+    		"----------\n" + 
+    		"1. ERROR in TBug372786.java (at line 1)\n" + 
+    		"	import jarred.TeamBug372786;\n" + 
+    		"	^\n" + 
+    		"The type notjarred.Missing cannot be resolved. It is indirectly referenced from required .class files\n" + 
+    		"----------\n",
+    		getClassLibraries("bug372786.jar"),
+    		false);
+    }
 }
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/ExternalizedRoles.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/ExternalizedRoles.java
index f8a3f93..7e0e155 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/ExternalizedRoles.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/ExternalizedRoles.java
@@ -1455,77 +1455,97 @@
 			    "}\n" +
 			    "        \n"
             },
-            "----------\n" + 
-    		"1. ERROR in Team167ratb5f_2.java (at line 8)\n" + 
-    		"	R<@base> r = getR2(getR1());\n" + 
-    		"	^\n" + 
-    		"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" + 
-    		"----------\n" + 
-    		"2. ERROR in Team167ratb5f_2.java (at line 11)\n" + 
-    		"	abstract R<@base> getR1();\n" + 
-    		"	         ^\n" + 
-    		"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" + 
-    		"----------\n" + 
-    		"3. ERROR in Team167ratb5f_2.java (at line 11)\n" + 
-    		"	abstract R<@base> getR1();\n" + 
-    		"	                  ^^^^^^^\n" + 
-    		"The abstract method getR1 in type R can only be defined by an abstract class\n" + 
-    		"----------\n" + 
-    		"4. ERROR in Team167ratb5f_2.java (at line 12)\n" + 
-    		"	R<@base> getR1() -> R<@base> getR1();\n" + 
-    		"	^\n" + 
-    		"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" + 
-    		"----------\n" + 
-    		"5. ERROR in Team167ratb5f_2.java (at line 12)\n" + 
-    		"	R<@base> getR1() -> R<@base> getR1();\n" + 
-    		"	                    ^\n" + 
-    		"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" + 
-    		"----------\n" + 
-    		"6. ERROR in Team167ratb5f_2.java (at line 12)\n" + 
-    		"	R<@base> getR1() -> R<@base> getR1();\n" + 
-    		"	                    ^\n" + 
-    		"Method designator binds to a method returning R1<@tthis[Team167ratb5f_1]> whereas return type R is specified (OTJLD 3.1(c)).\n" + 
-    		"----------\n" + 
-    		"7. ERROR in Team167ratb5f_2.java (at line 13)\n" + 
-    		"	abstract R<@base> getR2(R<@base> in);\n" + 
-    		"	         ^\n" + 
-    		"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" + 
-    		"----------\n" + 
-    		"8. ERROR in Team167ratb5f_2.java (at line 13)\n" + 
-    		"	abstract R<@base> getR2(R<@base> in);\n" + 
-    		"	                  ^^^^^^^^^^^^^^^^^^\n" + 
-    		"The abstract method getR2 in type R can only be defined by an abstract class\n" + 
-    		"----------\n" + 
-    		"9. ERROR in Team167ratb5f_2.java (at line 13)\n" + 
-    		"	abstract R<@base> getR2(R<@base> in);\n" + 
-    		"	                        ^\n" + 
-    		"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" + 
-    		"----------\n" + 
-    		"10. ERROR in Team167ratb5f_2.java (at line 14)\n" + 
-    		"	R<@base> getR2(R<@base> in) -> R<@base> getR2(R<@base>1 in); // here\n" + 
-    		"	^\n" + 
-    		"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" + 
-    		"----------\n" + 
-    		"11. ERROR in Team167ratb5f_2.java (at line 14)\n" + 
-    		"	R<@base> getR2(R<@base> in) -> R<@base> getR2(R<@base>1 in); // here\n" + 
-    		"	               ^\n" + 
-    		"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" + 
-    		"----------\n" + 
-    		"12. ERROR in Team167ratb5f_2.java (at line 14)\n" + 
-    		"	R<@base> getR2(R<@base> in) -> R<@base> getR2(R<@base>1 in); // here\n" + 
-    		"	                               ^\n" + 
-    		"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" + 
-    		"----------\n" + 
-    		"13. ERROR in Team167ratb5f_2.java (at line 14)\n" + 
-    		"	R<@base> getR2(R<@base> in) -> R<@base> getR2(R<@base>1 in); // here\n" + 
-    		"	                               ^^^^^^^^^^^^^^^\n" + 
-    		"No method getR2() found in type Team167ratb5f_1 to resolve method designator (OTJLD 3.1(c)).\n" + 
-    		"----------\n" + 
-    		"14. ERROR in Team167ratb5f_2.java (at line 14)\n" + 
-    		"	R<@base> getR2(R<@base> in) -> R<@base> getR2(R<@base>1 in); // here\n" + 
-    		"	                                                      ^\n" + 
-    		"Syntax error on token \"1\", delete this token\n" + 
-    		"----------\n");
+    		"----------\n" +
+			"1. ERROR in Team167ratb5f_2.java (at line 3)\n" +
+			"	public class R playedBy Team167ratb5f_1 {\n" +
+			"	             ^\n" +
+			"The type R must be an abstract class to define abstract methods\n" +
+			"----------\n" +
+			"2. ERROR in Team167ratb5f_2.java (at line 8)\n" +
+			"	R<@base> r = getR2(getR1());\n" +
+			"	^\n" +
+			"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" +
+			"----------\n" +
+			"3. ERROR in Team167ratb5f_2.java (at line 8)\n" +
+			"	R<@base> r = getR2(getR1());\n" +
+			"	             ^^^^^\n" +
+			"The method getR2(R<@tthis[Team167ratb5f_2]>) in the type Team167ratb5f_2.R is not applicable for the arguments (R)\n" +
+			"----------\n" +
+			"4. ERROR in Team167ratb5f_2.java (at line 9)\n" +
+			"	r.test();\n" +
+			"	^\n" +
+			"The type R is not visible\n" +
+			"----------\n" +
+			"5. ERROR in Team167ratb5f_2.java (at line 11)\n" +
+			"	abstract R<@base> getR1();\n" +
+			"	         ^\n" +
+			"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" +
+			"----------\n" +
+			"6. ERROR in Team167ratb5f_2.java (at line 11)\n" +
+			"	abstract R<@base> getR1();\n" +
+			"	         ^^^^^^^^\n" +
+			"The return type is incompatible with Team167ratb5f_2.R.getR1()\n" +
+			"----------\n" +
+			"7. ERROR in Team167ratb5f_2.java (at line 12)\n" +
+			"	R<@base> getR1() -> R<@base> getR1();\n" +
+			"	^\n" +
+			"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" +
+			"----------\n" +
+			"8. ERROR in Team167ratb5f_2.java (at line 12)\n" +
+			"	R<@base> getR1() -> R<@base> getR1();\n" +
+			"	^\n" +
+			"Method designator binds to a method returning R whereas return type R is specified (OTJLD 3.1(c)).\n" +
+			"----------\n" +
+			"9. ERROR in Team167ratb5f_2.java (at line 12)\n" +
+			"	R<@base> getR1() -> R<@base> getR1();\n" +
+			"	                    ^\n" +
+			"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" +
+			"----------\n" +
+			"10. ERROR in Team167ratb5f_2.java (at line 12)\n" +
+			"	R<@base> getR1() -> R<@base> getR1();\n" +
+			"	                    ^\n" +
+			"Method designator binds to a method returning R1<@tthis[Team167ratb5f_1]> whereas return type R is specified (OTJLD 3.1(c)).\n" +
+			"----------\n" +
+			"11. ERROR in Team167ratb5f_2.java (at line 13)\n" +
+			"	abstract R<@base> getR2(R<@base> in);\n" +
+			"	         ^\n" +
+			"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" +
+			"----------\n" +
+			"12. ERROR in Team167ratb5f_2.java (at line 13)\n" +
+			"	abstract R<@base> getR2(R<@base> in);\n" +
+			"	                  ^^^^^^^^^^^^^^^^^^\n" +
+			"The abstract method getR2 in type R can only be defined by an abstract class\n" +
+			"----------\n" +
+			"13. ERROR in Team167ratb5f_2.java (at line 13)\n" +
+			"	abstract R<@base> getR2(R<@base> in);\n" +
+			"	                        ^\n" +
+			"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" +
+			"----------\n" +
+			"14. ERROR in Team167ratb5f_2.java (at line 14)\n" +
+			"	R<@base> getR2(R<@base> in) -> R<@base> getR2(R<@base>1 in); // here\n" +
+			"	^\n" +
+			"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" +
+			"----------\n" +
+			"15. ERROR in Team167ratb5f_2.java (at line 14)\n" +
+			"	R<@base> getR2(R<@base> in) -> R<@base> getR2(R<@base>1 in); // here\n" +
+			"	               ^\n" +
+			"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" +
+			"----------\n" +
+			"16. ERROR in Team167ratb5f_2.java (at line 14)\n" +
+			"	R<@base> getR2(R<@base> in) -> R<@base> getR2(R<@base>1 in); // here\n" +
+			"	                               ^\n" +
+			"Illegal use of value parameter: type Team167ratb5f_2.R does not declare a value parameter at position 1 (OTJLD 9.2.1).\n" +
+			"----------\n" +
+			"17. ERROR in Team167ratb5f_2.java (at line 14)\n" +
+			"	R<@base> getR2(R<@base> in) -> R<@base> getR2(R<@base>1 in); // here\n" +
+			"	                               ^^^^^^^^^^^^^^^\n" +
+			"No method getR2() found in type Team167ratb5f_1 to resolve method designator (OTJLD 3.1(c)).\n" +
+			"----------\n" +
+			"18. ERROR in Team167ratb5f_2.java (at line 14)\n" +
+			"	R<@base> getR2(R<@base> in) -> R<@base> getR2(R<@base>1 in); // here\n" +
+			"	                                                      ^\n" +
+			"Syntax error on token \"1\", delete this token\n" +
+			"----------\n");
     }
 
     // a role is externalized relative to the base reference - used in callin signature
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/FileStructure.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/FileStructure.java
index 85b8de2..0d3e53f 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/FileStructure.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/rolesandteams/FileStructure.java
@@ -1576,38 +1576,39 @@
 			    "protected class R1517nrf5 {}\n" +
 			    "    \n"
             },
-            "----------\n" + 
-            "1. ERROR in "+convertedOutputPath+"p\\Team1517nrf5\\Mid1517nrf5.java (at line 3)\n" + 
-            "	public team class Mid1517nrf5 {}\n" + 
-            "    \n" + 
-            "	                            ^^^^^^^^^\n" + 
-            "The return type is incompatible with Team1517nrf5.Mid1517nrf5.R1517nrf5()\n" + 
-            "----------\n" + 
-            "----------\n" + 
-            "1. ERROR in "+convertedOutputPath+"p\\Team1517nrf5\\Mid1517nrf5\\R1517nrf5.java (at line 3)\n" + 
-            "	protected class R1517nrf5 {}\n" + 
-            "	                ^^^^^^^^^\n" + 
-            "Missing anchor (team instance) for role type p.Team1517nrf5.Mid1517nrf5.R1517nrf5 outside its team context (OTJLD 1.2.2(b)).\n" + 
-            "----------\n" + 
+    		"----------\n" + 
+			"1. ERROR in "+convertedOutputPath+"p\\Team1517nrf5.java (at line 4)\n" + 
+			"	\n" + 
+			"\n" + 
+			"	^^^\n" + 
+			"Type mismatch: cannot convert from Mid1517nrf5<@tthis[Team1517nrf5]> to Mid1517nrf5<@tthis[Team1517nrf5]>\n" + 
+			"----------\n" + 
+			"----------\n" + 
+			"1. ERROR in "+convertedOutputPath+"p\\Team1517nrf5\\Mid1517nrf5.java (at line 3)\n" + 
+			"	public team class Mid1517nrf5 {}\n" + 
+			"    \n" + 
+			"	                            ^^^^^^^^^\n" + 
+			"The return type is incompatible with Team1517nrf5.Mid1517nrf5.R1517nrf5()\n" + 
+			"----------\n" + 
             // this is the main error message, the others are mostly caused by compilation order issues:
-            "----------\n" + 
-            "1. ERROR in p\\Team1517nrf5\\Mid1517nrf5\\R1517nrf5\\Deep1517nrf5.java (at line 3)\n" + 
-            "	protected class Deep1517nrf5 {}\n" + 
-            "	                ^^^^^^^^^^^^\n" + 
-            "Member types not allowed in regular roles. Mark class p.Team1517nrf5.Mid1517nrf5.R1517nrf5 as a team if Deep1517nrf5 should be its role (OTJLD 1.5(a,b)). \n" + 
-            "----------\n" + 
-            "----------\n" + 
-            "1. ERROR in p\\Team1517nrf5.java (at line 3)\n" + 
-            "	public team class Team1517nrf5 {}\n" + 
-            "	                  ^^^^^^^^^^^^\n" + 
-            "The type Team1517nrf5 is already defined\n" + 
-            "----------\n" + 
-            "----------\n" + 
-            "1. ERROR in p\\Team1517nrf5\\Mid1517nrf5.java (at line 3)\n" + 
-            "	public team class Mid1517nrf5 {}\n" + 
-            "	                  ^^^^^^^^^^^\n" + 
-            "Duplicate nested type Mid1517nrf5\n" + 
-            "----------\n");
+			"----------\n" + 
+			"1. ERROR in p\\Team1517nrf5\\Mid1517nrf5\\R1517nrf5\\Deep1517nrf5.java (at line 3)\n" + 
+			"	protected class Deep1517nrf5 {}\n" + 
+			"	                ^^^^^^^^^^^^\n" + 
+			"Member types not allowed in regular roles. Mark class p.Team1517nrf5.Mid1517nrf5.R1517nrf5 as a team if Deep1517nrf5 should be its role (OTJLD 1.5(a,b)). \n" + 
+			"----------\n" + 
+			"----------\n" + 
+			"1. ERROR in p\\Team1517nrf5.java (at line 3)\n" + 
+			"	public team class Team1517nrf5 {}\n" + 
+			"	                  ^^^^^^^^^^^^\n" + 
+			"The type Team1517nrf5 is already defined\n" + 
+			"----------\n" + 
+			"----------\n" + 
+			"1. ERROR in p\\Team1517nrf5\\Mid1517nrf5.java (at line 3)\n" + 
+			"	public team class Mid1517nrf5 {}\n" + 
+			"	                  ^^^^^^^^^^^\n" + 
+			"Duplicate nested type Mid1517nrf5\n" + 
+			"----------\n");
     }
 
     // empty classes - 4 levels : OK
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/testresources/bug372786.jar b/testplugins/org.eclipse.objectteams.otdt.tests/testresources/bug372786.jar
new file mode 100644
index 0000000..ba10430
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/testresources/bug372786.jar
Binary files differ