RFR: 8297158: Suspicious collection method call in Types.isSameTypeVisitor
Vicente Romero
vromero at openjdk.org
Sun Jan 29 02:26:54 UTC 2023
On Sun, 29 Jan 2023 02:20:10 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> As reported there is a code in `com.sun.tools.javac.code.Types` that was basically a no-op. The code in question is:
>
>
> if (tMap.containsKey(ti)) {
> throw new AssertionError("Malformed intersection");
> }
> tMap.put(ti.tsym, ti);
>
> where tMap is defined as: `Map<Symbol,Type>`, but `ti` is a type so the condition, `tMap.containsKey(ti)`, is always false. The assertion should be thrown if an intersection type has two or more repeated interfaces. But there are other places in the compiler where this is checked for and an error is issued. So it shouldn't be possible to get to this point during a compilation. There are several tests, including combo tests, already stressing this code for this reason there is no need to add more regression tests.
>
> TIA
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 5119:
> 5117:
> 5118: Type checkIntersection(JCTree tree, List<JCExpression> bounds) {
> 5119: Set<Symbol> boundSet = new HashSet<>();
this set had the same issue, two different Type instances can refer to the same type but the `tsym` field they have should point to a common symbol. This is why we should have a set on these symbols
-------------
PR: https://git.openjdk.org/jdk/pull/12279
More information about the compiler-dev
mailing list