Bug 391876 - false-report (nested class): interface cannot be
implemented more than once
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
index 2e10aa9..076125c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
@@ -542,7 +542,8 @@
 					types.add(this.environment.getTypeFromTypeSignature(wrapper, typeVars, this, missingTypeNames));
   :giro*/
 					TypeBinding type = this.environment.getTypeFromTypeSignature(wrapper, typeVars, this, missingTypeNames);
-					if (!(type instanceof ReferenceBinding && TSuperHelper.isTSubOf(this, (ReferenceBinding) type)))
+					if (this.isDirectRole()
+							&& !(type instanceof ReferenceBinding && TSuperHelper.isTSubOf(this, (ReferenceBinding) type)))
 						type = RoleTypeCreator.maybeWrapUnqualifiedRoleType(type, this);
 					types.add(type);
 // SH}
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 033c5b0..a4a3424 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
@@ -40,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[] { "testBug372786"};
+//		TESTS_NAMES = new String[] { "testBug391876"};
 //		TESTS_NUMBERS = new int[] { 1459 };
 //		TESTS_RANGE = new int[] { 1097, -1 };
 	}
@@ -5251,4 +5251,45 @@
     		getClassLibraries("bug372786.jar"),
     		false);
     }
+
+    // Bug 391876 - false-report (nested class): interface cannot be implemented more than once
+    // bogus error seen: the interface NonUniqueIndex cannot be implemented more than once[...]
+    public void testBug391876() {
+    	runConformTest(
+    		new String[] {
+    			"p/Entity.java",
+    				"package p;\n" +
+					"public interface Entity{}\n",
+    			"p/Index.java",
+    				"package p;\n" +
+    				"public interface Index<T extends Entity> {}\n",
+    			"p/NonUniqueIndex.java",
+	    			"package p;\n" +
+	    			"public interface NonUniqueIndex<V extends Entity, T> extends Index<V> {}\n",
+    			"p/User.java",
+    				"package p;\n" +
+    				"public interface User extends Entity {}",
+    			"p/UserByCustomerIndex.java",
+    				"package p;\n" +
+    				"public interface UserByCustomerIndex extends NonUniqueIndex<User, UserByCustomerIndex.UserByCustomerKey> {\n" + 
+    				"	class UserByCustomerKey {}\n" +
+    				"}",
+    			"p3/NonUniqueIndexImpl.java",
+    				"package p3;\n" +
+    				"import p.*;\n" +
+    				"public class NonUniqueIndexImpl<V extends Entity, T> implements NonUniqueIndex<V, T> {}\n",
+    		},
+    		"");
+    	runConformTest(
+			new String[] {
+				"p2/UserByCustomerIndexImpl.java",
+				"package p2;\n" +
+						"import p.*;\n" +
+						"import p3.NonUniqueIndexImpl;\n" +
+						"public class UserByCustomerIndexImpl \n" +
+						"		extends NonUniqueIndexImpl<User, UserByCustomerIndex.UserByCustomerKey>\n" +
+						"		implements UserByCustomerIndex {}\n",
+			},
+			"", null, false/*flush*/, null);
+    }
 }