RFR: JDK-8193367: Annotated type variable bounds crash javac

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Jun 11 17:23:07 UTC 2018


I think this patch is a good start, but to be complete, we'd need to 
completely virtualize access on the 'bound' field, otherwise we risk 
turning this into a whack-a-mole exercise. There are e.g. 30 usages in 
Types alone, each of those could lead to issues with type annos.

Maurizio



On 11/06/18 15:42, B. Blaser wrote:
> Hi,
>
> By the light of Maurizio's JBS comment [1], I suggest the following
> fix which virtualizes and overrides 'TypeVar.bound()' in the cloned
> type var and uses it in 'Types.getBounds()'.
>
> Any comment is welcome (langtools:tier1 is OK),
> Bernard
>
> [1] https://bugs.openjdk.java.net/browse/JDK-8193367
>
>
> diff -r 65e65d5905bc
> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java
> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java
>     Sun Jun 10 12:58:38 2018 +0300
> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java
>     Mon Jun 11 15:50:12 2018 +0200
> @@ -1636,11 +1636,16 @@
>               this.lower = lower;
>           }
>
> +        public Type bound() { return bound; }
> +
>           @Override
>           public TypeVar cloneWithMetadata(TypeMetadata md) {
>               return new TypeVar(tsym, bound, lower, md) {
>                   @Override
>                   public Type baseType() { return TypeVar.this.baseType(); }
> +
> +                @Override
> +                public Type bound() { return TypeVar.this.bound; }
>               };
>           }
>
> diff -r 65e65d5905bc
> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
>     Sun Jun 10 12:58:38 2018 +0300
> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
>     Mon Jun 11 15:50:12 2018 +0200
> @@ -2666,10 +2666,10 @@
>        * Return list of bounds of the given type variable.
>        */
>       public List<Type> getBounds(TypeVar t) {
> -        if (t.bound.hasTag(NONE))
> +        if (t.bound().hasTag(NONE))
>               return List.nil();
> -        else if (t.bound.isErroneous() || !t.bound.isCompound())
> -            return List.of(t.bound);
> +        else if (t.bound().isErroneous() || !t.bound().isCompound())
> +            return List.of(t.bound());
>           else if ((erasure(t).tsym.flags() & INTERFACE) == 0)
>               return interfaces(t).prepend(supertype(t));
>           else
> diff -r 65e65d5905bc
> test/langtools/tools/javac/generics/typevars/AnnoTypeVarBounds.java
> --- /dev/null    Thu Jan 01 00:00:00 1970 +0000
> +++ b/test/langtools/tools/javac/generics/typevars/AnnoTypeVarBounds.java
>     Mon Jun 11 15:50:12 2018 +0200
> @@ -0,0 +1,15 @@
> +/*
> + * @test
> + * @bug     8193367
> + * @summary Annotated type variable bounds crash javac
> + * @compile AnnoTypeVarBounds.java
> + */
> +import java.lang.annotation.ElementType;
> +import java.lang.annotation.Target;
> +
> +class AnnoTypeVarBounds {
> +    @Target(value = {ElementType.TYPE_USE})
> +    @interface A{}
> +    class Sup<X, Y> { }
> +    class Sub<U extends @A V, @A V extends String> extends Sup<U, V> { }
> +}



More information about the compiler-dev mailing list