7090499: missing rawtypes warnings in anonymous inner class
Summary: javac does not detect raw types inside anonymous inner classes
Reviewed-by: jjg
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Sep 23 23:30:31 2011 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Oct 06 18:39:31 2011 +0100
@@ -1169,12 +1169,17 @@
if (lint.isEnabled(LintCategory.RAW) &&
tree.type.tag == CLASS &&
!TreeInfo.isDiamond(tree) &&
- !env.enclClass.name.isEmpty() && //anonymous or intersection
+ !withinAnonConstr(env) &&
tree.type.isRaw()) {
log.warning(LintCategory.RAW,
tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type);
}
}
+
+ boolean withinAnonConstr(Env<AttrContext> env) {
+ return env.enclClass.name.isEmpty() &&
+ env.enclMethod != null && env.enclMethod.name == names.init;
+ }
}
/* *************************************************************************
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/warnings/7090499/T7090499.java Thu Oct 06 18:39:31 2011 +0100
@@ -0,0 +1,37 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug 7094099
+ * @summary -Xlint:rawtypes
+ * @compile/fail/ref=T7090499.out -XDrawDiagnostics -Xlint:rawtypes T7090499.java
+ */
+
+
+class T7090499<E> {
+
+ static class B<X> {}
+
+ class A<X> {
+ class X {}
+ class Z<Y> {}
+ }
+
+ T7090499 t = new T7090499() { //raw warning (2)
+
+ A.X x1;//raw warning
+ A.Z z1;//raw warning
+
+ T7090499.B<Integer> b1;//ok
+ T7090499.B b2;//raw warning
+
+ A<String>.X x2;//ok
+ A<String>.Z<Integer> z2;//ok
+ A<B>.Z<A<B>> z3;//raw warning (2)
+
+ void test(Object arg1, B arg2) {//raw warning
+ boolean b = arg1 instanceof A;//ok
+ Object a = (A)arg1;//ok
+ A a2 = new A() {};//raw warning (2)
+ a2.new Z() {};//raw warning
+ }
+ };
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/warnings/7090499/T7090499.out Thu Oct 06 18:39:31 2011 +0100
@@ -0,0 +1,17 @@
+T7090499.java:18:5: compiler.warn.raw.class.use: T7090499, T7090499<E>
+T7090499.java:18:22: compiler.warn.raw.class.use: T7090499, T7090499<E>
+T7090499.java:20:10: compiler.warn.raw.class.use: T7090499.A.X, T7090499<E>.A<X>.X
+T7090499.java:21:10: compiler.warn.raw.class.use: T7090499.A.Z, T7090499<E>.A<X>.Z<Y>
+T7090499.java:24:17: compiler.warn.raw.class.use: T7090499.B, T7090499.B<X>
+T7090499.java:26:10: compiler.err.improperly.formed.type.inner.raw.param
+T7090499.java:27:10: compiler.err.improperly.formed.type.inner.raw.param
+T7090499.java:28:18: compiler.warn.raw.class.use: T7090499.B, T7090499.B<X>
+T7090499.java:28:17: compiler.err.improperly.formed.type.inner.raw.param
+T7090499.java:28:11: compiler.warn.raw.class.use: T7090499.B, T7090499.B<X>
+T7090499.java:28:10: compiler.err.improperly.formed.type.inner.raw.param
+T7090499.java:30:32: compiler.warn.raw.class.use: T7090499.B, T7090499.B<X>
+T7090499.java:33:13: compiler.warn.raw.class.use: T7090499.A, T7090499<E>.A<X>
+T7090499.java:33:24: compiler.warn.raw.class.use: T7090499.A, T7090499<E>.A<X>
+T7090499.java:34:20: compiler.warn.raw.class.use: T7090499.A.Z, T7090499<E>.A<X>.Z<Y>
+4 errors
+11 warnings