--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Jul 27 19:01:08 2011 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Jul 27 19:01:33 2011 +0100
@@ -1375,8 +1375,10 @@
int oldmode = mode;
mode = TYPE;
boolean diamondFound = false;
+ int lastTypeargsPos = -1;
if (S.token() == LT) {
checkGenerics();
+ lastTypeargsPos = S.pos();
t = typeArguments(t, true);
diamondFound = (mode & DIAMOND) != 0;
}
@@ -1389,6 +1391,7 @@
S.nextToken();
t = toP(F.at(pos).Select(t, ident()));
if (S.token() == LT) {
+ lastTypeargsPos = S.pos();
checkGenerics();
t = typeArguments(t, true);
diamondFound = (mode & DIAMOND) != 0;
@@ -1397,7 +1400,11 @@
mode = oldmode;
if (S.token() == LBRACKET) {
JCExpression e = arrayCreatorRest(newpos, t);
- if (typeArgs != null) {
+ if (diamondFound) {
+ reportSyntaxError(lastTypeargsPos, "cannot.create.array.with.diamond");
+ return toP(F.at(newpos).Erroneous(List.of(e)));
+ }
+ else if (typeArgs != null) {
int pos = newpos;
if (!typeArgs.isEmpty() && typeArgs.head.pos != Position.NOPOS) {
// note: this should always happen but we should