This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch GROOVY_2_5_X in repository https://gitbox.apache.org/repos/asf/groovy.git
commit b1fb94bff00617a90a93ba4f4dc29a6816a9d22c Author: Paul King <pa...@asert.com.au> AuthorDate: Fri May 24 11:45:47 2019 +1000 GROOVY-9141: add null check for classNode when checking for abstract method with body (tweaks) --- .../codehaus/groovy/antlr/AntlrParserPlugin.java | 9 ++++---- src/test/groovy/bugs/Groovy9141.groovy | 27 +++++++++++----------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java index 81ac6a4..dee0a95 100644 --- a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java +++ b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java @@ -921,12 +921,11 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy modifiers &= ~Opcodes.ACC_SYNTHETIC; methodNode = new MethodNode(name, modifiers, returnType, parameters, exceptions, code); if ((modifiers & Opcodes.ACC_ABSTRACT) == 0) { - if (node != null) { - assertNodeType(SLIST, node); - code = statementList(node); - } else { - throw new ASTRuntimeException(methodDef, "You defined a method without body. Try adding a body, or declare it abstract."); + if (node == null) { + throw new ASTRuntimeException(methodDef, "You defined a method without a body. Try adding a body, or declare it abstract."); } + assertNodeType(SLIST, node); + code = statementList(node); } else if (node != null) { if (classNode != null && classNode.isAnnotationDefinition()) { code = statement(node); diff --git a/src/test/groovy/bugs/Groovy9141.groovy b/src/test/groovy/bugs/Groovy9141.groovy index 32dd3a4..97d986c 100644 --- a/src/test/groovy/bugs/Groovy9141.groovy +++ b/src/test/groovy/bugs/Groovy9141.groovy @@ -23,24 +23,23 @@ import groovy.transform.CompileStatic @CompileStatic final class Groovy9141 extends CompilableTestSupport { + private static final String METHOD_DEF = ''' + abstract meth() { + println 42 + } + ''' - void testAbstractMethodWithBody1() { - def err = shouldNotCompile '''\ - abstract def meth() { - println 42 - } - '''.stripIndent() - assert err =~ / You can not define a abstract method\[meth\] in the script. Try removing the 'abstract' / + void testAbstractMethodWithBodyInScript() { + def err = shouldNotCompile METHOD_DEF + assert err =~ / Abstract methods do not define a body. / } - void testAbstractMethodWithBody2() { - def err = shouldNotCompile '''\ + void testAbstractMethodWithBodyInClass() { + def err = shouldNotCompile """ class Main { - abstract def meth() { - println 42 - } + $METHOD_DEF } - '''.stripIndent() - assert err =~ / Can't have an abstract method in a non-abstract class. / + """ + assert err =~ / Abstract methods do not define a body. / } }