--- a/langtools/test/tools/javac/generics/diamond/6996914/T6996914a.java Sat Mar 28 10:18:27 2015 -0700
+++ b/langtools/test/tools/javac/generics/diamond/6996914/T6996914a.java Mon Mar 30 17:09:14 2015 +0530
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2015, 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
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 6996914 7020044
+ * @bug 6996914 7020044 8062373
* @summary Diamond inference: problem when accessing protected constructor
* @run main T6996914a
*/
@@ -53,6 +53,17 @@
}
}
+ enum DiamondKind {
+ STANDARD("new Foo<>();"),
+ ANON("new Foo<>() {};");
+
+ String expr;
+
+ DiamondKind(String expr) {
+ this.expr = expr;
+ }
+ }
+
enum ConstructorKind {
PACKAGE(""),
PROTECTED("protected"),
@@ -93,14 +104,14 @@
final static String sourceStub =
"#I\n" +
"class Test {\n" +
- " Foo<String> fs = new Foo<>();\n" +
+ " Foo<String> fs = #D\n" +
"}\n";
String source;
- public ClientClass(PackageKind pk) {
+ public ClientClass(PackageKind pk, DiamondKind dk) {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
- source = sourceStub.replace("#I", pk.importDecl);
+ source = sourceStub.replace("#I", pk.importDecl).replace("#D", dk.expr);
}
@Override
@@ -112,20 +123,22 @@
public static void main(String... args) throws Exception {
for (PackageKind pk : PackageKind.values()) {
for (ConstructorKind ck : ConstructorKind.values()) {
- compileAndCheck(pk, ck);
+ for (DiamondKind dk : DiamondKind.values()) {
+ compileAndCheck(pk, ck, dk);
+ }
}
}
}
- static void compileAndCheck(PackageKind pk, ConstructorKind ck) throws Exception {
+ static void compileAndCheck(PackageKind pk, ConstructorKind ck, DiamondKind dk) throws Exception {
FooClass foo = new FooClass(pk, ck);
- ClientClass client = new ClientClass(pk);
+ ClientClass client = new ClientClass(pk, dk);
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
ErrorListener el = new ErrorListener();
JavacTask ct = (JavacTask)tool.getTask(null, null, el,
null, null, Arrays.asList(foo, client));
ct.analyze();
- if (el.errors > 0 == check(pk, ck)) {
+ if (el.errors > 0 == check(pk, ck, dk)) {
String msg = el.errors > 0 ?
"Error compiling files" :
"No error when compiling files";
@@ -133,9 +146,10 @@
}
}
- static boolean check(PackageKind pk, ConstructorKind ck) {
+ static boolean check(PackageKind pk, ConstructorKind ck, DiamondKind dk) {
switch (pk) {
- case A: return ck == ConstructorKind.PUBLIC;
+ case A: return ck == ConstructorKind.PUBLIC ||
+ (ck == ConstructorKind.PROTECTED && dk == DiamondKind.ANON);
case DEFAULT: return ck != ConstructorKind.PRIVATE;
default: throw new AssertionError("Unknown package kind");
}