8215482: check for cycles in type variables can provoke NPE
Reviewed-by: mcimadamore
This commit is contained in:
parent
88366150c6
commit
ae0cb515d6
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -794,7 +794,7 @@ public class Attr extends JCTree.Visitor {
|
|||||||
* @param typarams the type variables to enter
|
* @param typarams the type variables to enter
|
||||||
* @param env the current environment
|
* @param env the current environment
|
||||||
*/
|
*/
|
||||||
void attribTypeVariables(List<JCTypeParameter> typarams, Env<AttrContext> env) {
|
void attribTypeVariables(List<JCTypeParameter> typarams, Env<AttrContext> env, boolean checkCyclic) {
|
||||||
for (JCTypeParameter tvar : typarams) {
|
for (JCTypeParameter tvar : typarams) {
|
||||||
TypeVar a = (TypeVar)tvar.type;
|
TypeVar a = (TypeVar)tvar.type;
|
||||||
a.tsym.flags_field |= UNATTRIBUTED;
|
a.tsym.flags_field |= UNATTRIBUTED;
|
||||||
@ -811,8 +811,10 @@ public class Attr extends JCTree.Visitor {
|
|||||||
}
|
}
|
||||||
a.tsym.flags_field &= ~UNATTRIBUTED;
|
a.tsym.flags_field &= ~UNATTRIBUTED;
|
||||||
}
|
}
|
||||||
for (JCTypeParameter tvar : typarams) {
|
if (checkCyclic) {
|
||||||
chk.checkNonCyclic(tvar.pos(), (TypeVar)tvar.type);
|
for (JCTypeParameter tvar : typarams) {
|
||||||
|
chk.checkNonCyclic(tvar.pos(), (TypeVar)tvar.type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -103,7 +103,7 @@ public class MemberEnter extends JCTree.Visitor {
|
|||||||
|
|
||||||
// Enter and attribute type parameters.
|
// Enter and attribute type parameters.
|
||||||
List<Type> tvars = enter.classEnter(typarams, env);
|
List<Type> tvars = enter.classEnter(typarams, env);
|
||||||
attr.attribTypeVariables(typarams, env);
|
attr.attribTypeVariables(typarams, env, true);
|
||||||
|
|
||||||
// Enter and attribute value parameters.
|
// Enter and attribute value parameters.
|
||||||
ListBuffer<Type> argbuf = new ListBuffer<>();
|
ListBuffer<Type> argbuf = new ListBuffer<>();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -831,8 +831,8 @@ public class TypeEnter implements Completer {
|
|||||||
|
|
||||||
annotate.annotateLater(tree.mods.annotations, baseEnv,
|
annotate.annotateLater(tree.mods.annotations, baseEnv,
|
||||||
sym, tree.pos());
|
sym, tree.pos());
|
||||||
|
attr.attribTypeVariables(tree.typarams, baseEnv, false);
|
||||||
|
|
||||||
attr.attribTypeVariables(tree.typarams, baseEnv);
|
|
||||||
for (JCTypeParameter tp : tree.typarams)
|
for (JCTypeParameter tp : tree.typarams)
|
||||||
annotate.queueScanTreeAndTypeAnnotate(tp, baseEnv, sym, tree.pos());
|
annotate.queueScanTreeAndTypeAnnotate(tp, baseEnv, sym, tree.pos());
|
||||||
|
|
||||||
@ -939,6 +939,12 @@ public class TypeEnter implements Completer {
|
|||||||
env.info.scope.enter(superSym);
|
env.info.scope.enter(superSym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!tree.typarams.isEmpty()) {
|
||||||
|
for (JCTypeParameter tvar : tree.typarams) {
|
||||||
|
chk.checkNonCyclic(tvar, (TypeVar)tvar.type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
finishClass(tree, env);
|
finishClass(tree, env);
|
||||||
|
|
||||||
if (allowTypeAnnos) {
|
if (allowTypeAnnos) {
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8215482
|
||||||
|
* @summary check for cycles in type variables can provoke NPE
|
||||||
|
* @compile NPETypeVarWithOuterBoundTest.java
|
||||||
|
*/
|
||||||
|
|
||||||
|
class NPETypeVarWithOuterBoundTest <A extends NPETypeVarWithOuterBoundTest.Inner, B> {
|
||||||
|
class Inner<F extends B> {}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user