Skip to content

Commit

Permalink
Null-Analysis - The interface ... cannot be implemented more than once
Browse files Browse the repository at this point in the history
with different arguments ...

fixes eclipse-jdt#2158
  • Loading branch information
stephan-herrmann committed Mar 17, 2024
1 parent 7dbb298 commit 33667c9
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,13 @@ public void updateSupertypesWithAnnotations(Map<ReferenceBinding,ReferenceBindin
protected ReferenceBinding updateWithAnnotations(TypeReference typeRef, ReferenceBinding previousType,
Map<ReferenceBinding, ReferenceBinding> outerUpdates, Map<ReferenceBinding, ReferenceBinding> updates)
{
if (previousType instanceof ParameterizedTypeBinding previousPTB
&& previousPTB.original() instanceof SourceTypeBinding previousOriginal
&& previousOriginal.supertypeAnnotationsUpdated) {
// re-initialized parameterized type with updated annotations from the original:
typeRef.resolvedType = this.scope.environment().createParameterizedType(previousOriginal, previousPTB.arguments, previousType.enclosingType());
}

typeRef.updateWithAnnotations(this.scope, 0);
ReferenceBinding updatedType = (ReferenceBinding) typeRef.resolvedType;
if (updatedType instanceof ParameterizedTypeBinding) {
Expand All @@ -1940,8 +1947,10 @@ protected ReferenceBinding updateWithAnnotations(TypeReference typeRef, Referenc
if (previousType != null) {
if (previousType.id == TypeIds.T_JavaLangObject && ((this.binding.tagBits & TagBits.HierarchyHasProblems) != 0))
return previousType; // keep this cycle breaker
if (previousType != updatedType) //$IDENTITY-COMPARISON$
if (previousType != updatedType) { //$IDENTITY-COMPARISON$
updates.put(previousType, updatedType);
this.binding.supertypeAnnotationsUpdated = true;
}
}
return updatedType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public class SourceTypeBinding extends ReferenceBinding {
public boolean isVarArgs = false; // for record declaration
private FieldBinding[] implicitComponentFields; // cache
private MethodBinding[] recordComponentAccessors = null; // hash maybe an overkill
public boolean supertypeAnnotationsUpdated = false; // have any supertype annotations been updated during CompleteTypeBindingsSteps.INTEGRATE_ANNOTATIONS_IN_HIERARCHY?

public SourceTypeBinding(char[][] compoundName, PackageBinding fPackage, ClassScope scope) {
this.compoundName = compoundName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19242,4 +19242,69 @@ public boolean hasNext() {
"----------\n";
runner.runNegativeTest();
}

public void testGH2158() {
Runner runner = new Runner();
runner.testFiles = new String[] {
"abc/Connection.java",
"""
package abc;
public interface Connection<@org.eclipse.jdt.annotation.NonNull M> { }
""",
"abc/IncomingMessageData.java",
"""
package abc;
public interface IncomingMessageData<@org.eclipse.jdt.annotation.NonNull T> { }
""",
"abc/MessageHandlerRegistry.java",
"""
package abc;
import org.eclipse.jdt.annotation.*;
public interface MessageHandlerRegistry
<@NonNull C extends Connection<?>, @NonNull T, @NonNull D extends IncomingMessageData<T>> { }
""",
"abc/MessageHandlerRegistryImpl.java",
"""
package abc;
import org.eclipse.jdt.annotation.*;
public class MessageHandlerRegistryImpl
<@NonNull C extends Connection<?>, @NonNull T, @NonNull D extends IncomingMessageData<T>>
implements MessageHandlerRegistry<C, T, D> { }
""",
"abc/d/DConnection.java",
"""
package abc.d;
import abc.*;
import org.eclipse.jdt.annotation.*;
public interface DConnection extends Connection<@NonNull CharSequence> { }
""",
"abc/d/DIncomingMessageData.java",
"""
package abc.d;
import org.eclipse.jdt.annotation.*;
import abc.*;
public interface DIncomingMessageData extends IncomingMessageData<@NonNull CharSequence> { }
""",
"abc/d/DMessageHandlerRegistry.java",
"""
package abc.d;
import org.eclipse.jdt.annotation.*;
import abc.*;
public interface DMessageHandlerRegistry<@NonNull C extends DConnection>
extends MessageHandlerRegistry<C, @NonNull CharSequence, @NonNull DIncomingMessageData> { }
""",
"abc/d/DMessageHandlerRegistryImpl.java",
"""
package abc.d;
import org.eclipse.jdt.annotation.*;
import abc.*;
public class DMessageHandlerRegistryImpl<@NonNull C extends DConnection>
extends MessageHandlerRegistryImpl<C, @NonNull CharSequence, @NonNull DIncomingMessageData>
implements DMessageHandlerRegistry<C> { }
"""
};
runner.customOptions = getCompilerOptions();
runner.classLibraries = this.LIBS;
runner.runConformTest();
}
}

0 comments on commit 33667c9

Please sign in to comment.