Test & fix for Bug 366597 - [compiler] NPE with role ifc wrongly
interpreted as a team
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java
index 2cec1dc..6de353a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java
@@ -997,6 +997,10 @@
 						problemReporter().illegalModifierForAnnotationMemberType(sourceType);
 					else
 						problemReporter().illegalModifierForMemberInterface(sourceType);
+//{ObjectTeams: prevent downstream problems with types illegally marked as team:
+					modifiers &= ~ClassFileConstants.AccTeam;
+					this.referenceContext.modifiers &= ~ClassFileConstants.AccTeam;
+// SH}
 				}
 				/*
 				} else if (sourceType.isLocalType()) { //interfaces cannot be defined inside a method
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/Protections.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/Protections.java
index 42c17d7..ffc1867 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/Protections.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/Protections.java
@@ -84,8 +84,10 @@
                 if (!hasClassKindProblem(type.binding))
                 	scope.problemReporter().missingTeamForRoleWithMembers(type.binding, type.memberTypes[0]);
         		// avoid secondary errors
-        		modifiers |= AccTeam;
-        		type.modifiers |= AccTeam;
+                if (!type.isInterface()) { // setting AccTeam for interface would aggravate the situation
+                	modifiers |= AccTeam;
+                	type.modifiers |= AccTeam;
+                }
         		type.binding.tagBits |= TagBits.HasClassKindProblem;
         		type.getTeamModel(); // initialize
         		for (int i = 0; i < type.memberTypes.length; i++) {
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 1310815..1501ff2 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
@@ -39,7 +39,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_sh75"};
+//		TESTS_NAMES = new String[] { "testB11_sh9"};
 //		TESTS_NUMBERS = new int[] { 1459 };
 //		TESTS_RANGE = new int[] { 1097, -1 };
 	}
@@ -4430,6 +4430,94 @@
             false/*showWarningToken*/);    
     }
     
+    // Bug 366597 - [compiler] NPE with role ifc wrongly interpreted as a team
+    public void testB11_sh97() {
+    	runNegativeTest(new String[] {
+    			"t/T1.java",
+    			"package t;\n" +
+    			"import base b.Base;\n" +
+    			"public team class T1  {\n" +
+    			"    protected interface IR\n" +
+    			"    public class R2 playedBy Base {\n" +
+    			"        void bar() {\n" +
+    			"            this.foo();\n" +
+    			"        }\n" +
+    			"    }\n" +
+    			"}\n",
+    			"b/Base.java",
+    			"package b;\n" +
+    			"public class Base { void foo() {} }\n"
+    	}, 
+		"----------\n" +
+		"1. ERROR in t\\T1.java (at line 4)\n" +
+		"	protected interface IR\n" +
+		"	                    ^^\n" +
+		"Syntax error, insert \"InterfaceBody\" to complete ClassBodyDeclarations\n" +
+		"----------\n" +
+		"2. ERROR in t\\T1.java (at line 5)\n" +
+		"	public class R2 playedBy Base {\n" +
+		"	             ^^\n" +
+		"Member types not allowed in regular roles. Mark class t.T1.IR as a team if R2 should be its role (OTJLD 1.5(a,b)). \n" +
+		"----------\n" +
+		"3. ERROR in t\\T1.java (at line 7)\n" +
+		"	this.foo();\n" +
+		"	^^^^\n" +
+		"Missing anchor (team instance) for role type t.T1.IR.R2 outside its team context (OTJLD 1.2.2(b)).\n" +
+		"----------\n" +
+		"4. WARNING in t\\T1.java (at line 7)\n" +
+		"	this.foo();\n" +
+		"	^^^^^^^^^^\n" +
+		"Access restriction of method foo() in type b.Base is overridden by this method binding (OTJLD 3.4(a)).\n" +
+		"----------\n" +
+		"5. ERROR in t\\T1.java (at line 7)\n" +
+		"	this.foo();\n" +
+		"	^^^^^^^^^^\n" +
+		"Unresolved self call foo() is implicitly bound by an inferred callout (OTJLD 3.1(j)).\n" +
+		"----------\n");
+    }
+
+    // Bug 366597 - [compiler] NPE with role ifc wrongly interpreted as a team
+    public void testB11_sh98() {
+    	runNegativeTest(new String[] {
+    			"t/T1.java",
+    			"package t;\n" +
+    			"import base b.Base;\n" +
+    			"public team class T1 extends T0 {\n" +
+    			"    protected team interface IR {}\n" +
+    			"    @Override\n" +
+    			"    protected class R2 playedBy Base {\n" +
+    			"        void bar() {\n" +
+    			"            this.foo();\n" +
+    			"        }\n" +
+    			"    }\n" +
+    			"}\n",
+    			"t/T0.java",
+    			"package t;\n" +
+    			"public team class T0 {\n" +
+    			"    protected class R2 {}" +
+    			"}\n",
+    			"b/Base.java",
+    			"package b;\n" +
+    			"public class Base { void foo() {} }\n"
+    	}, 
+		"----------\n" + 
+		"1. ERROR in t\\T1.java (at line 4)\n" + 
+		"	protected team interface IR {}\n" + 
+		"	                         ^^\n" + 
+		"Illegal modifier for the member interface IR; only public, protected, private, static & abstract are permitted\n" + 
+		"----------\n" + 
+		"2. WARNING in t\\T1.java (at line 8)\n" + 
+		"	this.foo();\n" + 
+		"	^^^^^^^^^^\n" + 
+		"Access restriction of method foo() in type b.Base is overridden by this method binding (OTJLD 3.4(a)).\n" + 
+		"----------\n" + 
+		"3. ERROR in t\\T1.java (at line 8)\n" + 
+		"	this.foo();\n" + 
+		"	^^^^^^^^^^\n" + 
+		"Unresolved self call foo() is implicitly bound by an inferred callout (OTJLD 3.1(j)).\n" + 
+		"----------\n");
+    }
+
     // reported by Christine Hundt
     // B.1.1-otjld-ju-1
     public void testB11_ju1() {