7123100: javac fails with java.lang.StackOverflowError

Thu, 12 Jan 2012 15:28:34 +0000

author
mcimadamore
date
Thu, 12 Jan 2012 15:28:34 +0000
changeset 1178
133744729455
parent 1177
70d92518063e
child 1179
1e2f4f4fb9f7

7123100: javac fails with java.lang.StackOverflowError
Summary: Inference of under-constrained type-variables creates erroneous recursive wildcard types
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Infer.java file | annotate | diff | comparison | revisions
test/tools/javac/cast/7123100/T7123100a.java file | annotate | diff | comparison | revisions
test/tools/javac/cast/7123100/T7123100a.out file | annotate | diff | comparison | revisions
test/tools/javac/cast/7123100/T7123100b.java file | annotate | diff | comparison | revisions
test/tools/javac/cast/7123100/T7123100b.out file | annotate | diff | comparison | revisions
test/tools/javac/cast/7123100/T7123100c.java file | annotate | diff | comparison | revisions
test/tools/javac/cast/7123100/T7123100c.out file | annotate | diff | comparison | revisions
test/tools/javac/cast/7123100/T7123100d.java file | annotate | diff | comparison | revisions
test/tools/javac/cast/7123100/T7123100d.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Wed Jan 11 18:23:24 2012 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Jan 12 15:28:34 2012 +0000
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -332,25 +332,29 @@
    1.11              //replace uninferred type-vars
    1.12              targs = types.subst(targs,
    1.13                      that.tvars,
    1.14 -                    instaniateAsUninferredVars(undetvars, that.tvars));
    1.15 +                    instantiateAsUninferredVars(undetvars, that.tvars));
    1.16          }
    1.17          return chk.checkType(warn.pos(), that.inst(targs, types), to);
    1.18      }
    1.19      //where
    1.20 -    private List<Type> instaniateAsUninferredVars(List<Type> undetvars, List<Type> tvars) {
    1.21 +    private List<Type> instantiateAsUninferredVars(List<Type> undetvars, List<Type> tvars) {
    1.22 +        Assert.check(undetvars.length() == tvars.length());
    1.23          ListBuffer<Type> new_targs = ListBuffer.lb();
    1.24 -        //step 1 - create syntethic captured vars
    1.25 +        //step 1 - create synthetic captured vars
    1.26          for (Type t : undetvars) {
    1.27              UndetVar uv = (UndetVar)t;
    1.28              Type newArg = new CapturedType(t.tsym.name, t.tsym, uv.inst, syms.botType, null);
    1.29              new_targs = new_targs.append(newArg);
    1.30          }
    1.31          //step 2 - replace synthetic vars in their bounds
    1.32 +        List<Type> formals = tvars;
    1.33          for (Type t : new_targs.toList()) {
    1.34              CapturedType ct = (CapturedType)t;
    1.35              ct.bound = types.subst(ct.bound, tvars, new_targs.toList());
    1.36 -            WildcardType wt = new WildcardType(ct.bound, BoundKind.EXTENDS, syms.boundClass);
    1.37 +            WildcardType wt = new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass);
    1.38 +            wt.bound = (TypeVar)formals.head;
    1.39              ct.wildcard = wt;
    1.40 +            formals = formals.tail;
    1.41          }
    1.42          return new_targs.toList();
    1.43      }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/cast/7123100/T7123100a.java	Thu Jan 12 15:28:34 2012 +0000
     2.3 @@ -0,0 +1,16 @@
     2.4 +/*
     2.5 + * @test /nodynamiccopyright/
     2.6 + * @bug     7123100
     2.7 + * @summary javac fails with java.lang.StackOverflowError
     2.8 + * @compile/fail/ref=T7123100a.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100a.java
     2.9 + */
    2.10 +
    2.11 +class T7123100a {
    2.12 +    <E extends Enum<E>> E m() {
    2.13 +        return null;
    2.14 +    }
    2.15 +
    2.16 +    <Z> void test() {
    2.17 +        Z z = (Z)m();
    2.18 +    }
    2.19 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/cast/7123100/T7123100a.out	Thu Jan 12 15:28:34 2012 +0000
     3.3 @@ -0,0 +1,4 @@
     3.4 +T7123100a.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), compiler.misc.type.captureof: 1, ?, Z
     3.5 +- compiler.err.warnings.and.werror
     3.6 +1 error
     3.7 +1 warning
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/cast/7123100/T7123100b.java	Thu Jan 12 15:28:34 2012 +0000
     4.3 @@ -0,0 +1,12 @@
     4.4 +/*
     4.5 + * @test /nodynamiccopyright/
     4.6 + * @bug     7123100
     4.7 + * @summary javac fails with java.lang.StackOverflowError
     4.8 + * @compile/fail/ref=T7123100b.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100b.java
     4.9 + */
    4.10 +
    4.11 +class T7123100b {
    4.12 +    <Z> void test(Enum<?> e) {
    4.13 +        Z z = (Z)e;
    4.14 +    }
    4.15 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/cast/7123100/T7123100b.out	Thu Jan 12 15:28:34 2012 +0000
     5.3 @@ -0,0 +1,4 @@
     5.4 +T7123100b.java:10:18: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Enum<compiler.misc.type.captureof: 1, ?>, Z
     5.5 +- compiler.err.warnings.and.werror
     5.6 +1 error
     5.7 +1 warning
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/cast/7123100/T7123100c.java	Thu Jan 12 15:28:34 2012 +0000
     6.3 @@ -0,0 +1,16 @@
     6.4 +/*
     6.5 + * @test /nodynamiccopyright/
     6.6 + * @bug     7123100
     6.7 + * @summary javac fails with java.lang.StackOverflowError
     6.8 + * @compile/fail/ref=T7123100c.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100c.java
     6.9 + */
    6.10 +
    6.11 +class T7123100c {
    6.12 +    <E> E m(E e) {
    6.13 +        return null;
    6.14 +    }
    6.15 +
    6.16 +    <Z> void test(Enum<?> e) {
    6.17 +        Z z = (Z)m(e);
    6.18 +    }
    6.19 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/tools/javac/cast/7123100/T7123100c.out	Thu Jan 12 15:28:34 2012 +0000
     7.3 @@ -0,0 +1,4 @@
     7.4 +T7123100c.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Enum<compiler.misc.type.captureof: 1, ?>, Z
     7.5 +- compiler.err.warnings.and.werror
     7.6 +1 error
     7.7 +1 warning
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/tools/javac/cast/7123100/T7123100d.java	Thu Jan 12 15:28:34 2012 +0000
     8.3 @@ -0,0 +1,16 @@
     8.4 +/*
     8.5 + * @test /nodynamiccopyright/
     8.6 + * @bug     7123100
     8.7 + * @summary javac fails with java.lang.StackOverflowError
     8.8 + * @compile/fail/ref=T7123100d.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100d.java
     8.9 + */
    8.10 +
    8.11 +class T7123100d {
    8.12 +    <E extends Enum<E>> E m(Enum<E> e) {
    8.13 +        return null;
    8.14 +    }
    8.15 +
    8.16 +    <Z> void test(Enum<?> e) {
    8.17 +        Z z = (Z)m(e);
    8.18 +    }
    8.19 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/tools/javac/cast/7123100/T7123100d.out	Thu Jan 12 15:28:34 2012 +0000
     9.3 @@ -0,0 +1,4 @@
     9.4 +T7123100d.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), compiler.misc.type.captureof: 1, ?, Z
     9.5 +- compiler.err.warnings.and.werror
     9.6 +1 error
     9.7 +1 warning

mercurial