This commit is contained in:
Alejandro Murillo 2016-07-28 16:44:39 +00:00
commit fca2c3ce3f
8 changed files with 174 additions and 17 deletions

View File

@ -757,7 +757,9 @@ public class Modules extends JCTree.Visitor {
@Override
public void visitRequires(JCRequires tree) {
msym.directives = msym.directives.prepend(tree.directive);
if (tree.directive != null) {
msym.directives = msym.directives.prepend(tree.directive);
}
}
@Override
@ -1214,9 +1216,9 @@ public class Modules extends JCTree.Visitor {
private void checkCyclicDependencies(JCModuleDecl mod) {
for (JCDirective d : mod.directives) {
if (!d.hasTag(Tag.REQUIRES))
JCRequires rd;
if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null)
continue;
JCRequires rd = (JCRequires) d;
Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>();
List<ModuleSymbol> queue = List.of(rd.directive.module);
while (queue.nonEmpty()) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2016, 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
@ -85,6 +85,9 @@ public class JavacTypes implements javax.lang.model.util.Types {
@DefinedBy(Api.LANGUAGE_MODEL)
public boolean isSameType(TypeMirror t1, TypeMirror t2) {
if (t1.getKind() == TypeKind.WILDCARD || t2.getKind() == TypeKind.WILDCARD) {
return false;
}
return types.isSameType((Type) t1, (Type) t2);
}

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2016, 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 8161277
* @summary javax.lang.model.util.Types.isSameType(...) returns true on wildcards
* @library /tools/lib/types
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* jdk.compiler/com.sun.tools.javac.code
* jdk.compiler/com.sun.tools.javac.comp
* jdk.compiler/com.sun.tools.javac.tree
* jdk.compiler/com.sun.tools.javac.util
* jdk.compiler/com.sun.tools.javac.file
* jdk.compiler/com.sun.tools.javac.model
* @build TypeHarness
* @run main IsSameTypeWildcardTest
*/
import java.util.ArrayList;
import java.util.List;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.model.JavacTypes;
public class IsSameTypeWildcardTest extends TypeHarness {
StrToTypeFactory strToTypeFactory;
JavacTypes javacTypes;
public static void main(String... args) throws Exception {
new IsSameTypeWildcardTest().runTest();
}
public IsSameTypeWildcardTest() {
javacTypes = JavacTypes.instance(context);
}
void runTest() {
List<String> imports = new ArrayList<>();
imports.add("java.util.*");
strToTypeFactory = new StrToTypeFactory(null, imports, null);
Type listOfWildcard = strToTypeFactory.getType("List<?>");
com.sun.tools.javac.util.List<Type> arguments = listOfWildcard.getTypeArguments();
Assert.check(!javacTypes.isSameType(arguments.head, arguments.head),
"if any argument is a wildcard then result must be false");
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2016, 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.
*/
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.element.TypeElement;
import javax.lang.model.SourceVersion;
@SupportedAnnotationTypes("Blah")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class Processor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> tE, RoundEnvironment env) {
return true;
}
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2016, 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 8158224
* @summary NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
* @build Processor
* @compile/fail/ref=T8158224.out -XDrawDiagnostics -processor Processor mods/foo/module-info.java
*/
// No code here, this file is just to host test description.

View File

@ -0,0 +1,2 @@
module-info.java:4:14: compiler.err.module.not.found: nonexistent
1 error

View File

@ -0,0 +1,5 @@
/* /nodynamiccopyright/ */
module foo {
requires nonexistent;
}

View File

@ -22,6 +22,7 @@
*/
import java.net.URI;
import java.util.ArrayList;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@ -82,6 +83,7 @@ import static com.sun.tools.javac.util.List.*;
* The code then verifies that {@code [X:=Object,Y:=Object]A<X,Y> == A<Object,Object>}.
*
* @author mcimadamore
* @author vromero
*/
public class TypeHarness {
@ -91,19 +93,20 @@ public class TypeHarness {
protected Names names;
protected ReusableJavaCompiler tool;
protected Infer infer;
protected Context context;
protected Factory fac;
protected TypeHarness() {
Context ctx = new Context();
JavacFileManager.preRegister(ctx);
MyAttr.preRegister(ctx);
tool = new ReusableJavaCompiler(ctx);
types = Types.instance(ctx);
infer = Infer.instance(ctx);
chk = Check.instance(ctx);
predef = Symtab.instance(ctx);
names = Names.instance(ctx);
context = new Context();
JavacFileManager.preRegister(context);
MyAttr.preRegister(context);
tool = new ReusableJavaCompiler(context);
types = Types.instance(context);
infer = Infer.instance(context);
chk = Check.instance(context);
predef = Symtab.instance(context);
names = Names.instance(context);
fac = new Factory();
}
@ -411,8 +414,8 @@ public class TypeHarness {
public StrToTypeFactory(String pkg, java.util.List<String> imports, java.util.List<String> typeVarDecls) {
this.pkg = pkg;
this.imports = imports;
this.typeVarDecls = typeVarDecls;
this.typeVariables = from(typeVarDecls.stream()
this.typeVarDecls = typeVarDecls == null ? new ArrayList<>() : typeVarDecls;
this.typeVariables = from(this.typeVarDecls.stream()
.map(this::typeVarName)
.map(this::getType)
.collect(Collectors.toList())
@ -420,7 +423,7 @@ public class TypeHarness {
}
TypeVar getTypeVarFromStr(String name) {
if (typeVarDecls == null) {
if (typeVarDecls.isEmpty()) {
return null;
}
int index = typeVarDecls.indexOf(name);
@ -476,7 +479,7 @@ public class TypeHarness {
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
String impStmts = imports.size() > 0 ?
imports.stream().map(i -> "import " + i + ";").collect(Collectors.joining("\n")) : "";
String tvars = typeVarDecls.size() > 0 ?
String tvars = !typeVarDecls.isEmpty() ?
typeVarDecls.stream().collect(Collectors.joining(",", "<", ">")) : "";
return template
.replace("#Package", (pkg == null) ? "" : "package " + pkg + ";")