# HG changeset patch # User jlahoda # Date 1385476039 -3600 # Node ID f39003ba351f593f31f12ae8dfb5f812d63407af # Parent 2afdc45dcc5b2ecf9aeb6277edfd8c120dc6e48c 8026374: javac accepts void as a method parameter Summary: Changing Check.validate to reject void types. Reviewed-by: jjg, vromero diff -r 2afdc45dcc5b -r f39003ba351f langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Nov 26 13:33:33 2013 +0100 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Nov 26 15:27:19 2013 +0100 @@ -933,7 +933,8 @@ chk.validate(tree.typarams, localEnv); // Check that result type is well-formed. - chk.validate(tree.restype, localEnv); + if (tree.restype != null && !tree.restype.type.hasTag(VOID)) + chk.validate(tree.restype, localEnv); // Check that receiver type is well-formed. if (tree.recvparam != null) { diff -r 2afdc45dcc5b -r f39003ba351f langtools/src/share/classes/com/sun/tools/javac/comp/Check.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Tue Nov 26 13:33:33 2013 +0100 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Tue Nov 26 15:27:19 2013 +0100 @@ -1326,6 +1326,14 @@ tree.underlyingType.accept(this); } + @Override + public void visitTypeIdent(JCPrimitiveTypeTree that) { + if (that.type.hasTag(TypeTag.VOID)) { + log.error(that.pos(), "void.not.allowed.here"); + } + super.visitTypeIdent(that); + } + /** Default visitor method: do nothing. */ @Override diff -r 2afdc45dcc5b -r f39003ba351f langtools/test/tools/javac/declaration/method/MethodVoidParameter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/declaration/method/MethodVoidParameter.java Tue Nov 26 15:27:19 2013 +0100 @@ -0,0 +1,9 @@ +/* @test /nodynamiccopyright/ + * @bug 8026374 + * @summary Cannot use void as a variable type + * @compile/fail/ref=MethodVoidParameter.out -XDrawDiagnostics MethodVoidParameter.java + */ +public class MethodVoidParameter { + void method(void v) { } + void method(void... v) { } +} diff -r 2afdc45dcc5b -r f39003ba351f langtools/test/tools/javac/declaration/method/MethodVoidParameter.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/declaration/method/MethodVoidParameter.out Tue Nov 26 15:27:19 2013 +0100 @@ -0,0 +1,3 @@ +MethodVoidParameter.java:7:17: compiler.err.void.not.allowed.here +MethodVoidParameter.java:8:17: compiler.err.void.not.allowed.here +2 errors