You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by sh...@apache.org on 2017/02/02 14:05:11 UTC
groovy git commit: GROOVY-8069: Annotation based logging of complex
expression in closure throws GroovyCastException with SC (closes #487)
Repository: groovy
Updated Branches:
refs/heads/master 15a8c67aa -> ea28001ac
GROOVY-8069: Annotation based logging of complex expression in closure throws GroovyCastException with SC (closes #487)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/ea28001a
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/ea28001a
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/ea28001a
Branch: refs/heads/master
Commit: ea28001ac0c12e4ee44af96e6caf5fe2eb9931b7
Parents: 15a8c67
Author: Shil Sinha <sh...@apache.org>
Authored: Thu Feb 2 01:48:01 2017 -0500
Committer: Shil Sinha <sh...@apache.org>
Committed: Thu Feb 2 09:03:02 2017 -0500
----------------------------------------------------------------------
src/main/groovy/util/logging/Commons.java | 1 +
src/main/groovy/util/logging/Log.java | 1 +
src/main/groovy/util/logging/Log4j.java | 1 +
src/main/groovy/util/logging/Log4j2.java | 1 +
src/main/groovy/util/logging/Slf4j.java | 1 +
.../classgen/asm/sc/bugs/Groovy8069Bug.groovy | 55 ++++++++++++++++++++
6 files changed, 60 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/ea28001a/src/main/groovy/util/logging/Commons.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/logging/Commons.java b/src/main/groovy/util/logging/Commons.java
index cfb912f..7b1da7d 100644
--- a/src/main/groovy/util/logging/Commons.java
+++ b/src/main/groovy/util/logging/Commons.java
@@ -91,6 +91,7 @@ public @interface Commons {
logVariable,
"is" + methodName.substring(0, 1).toUpperCase(Locale.ENGLISH) + methodName.substring(1, methodName.length()) + "Enabled",
ArgumentListExpression.EMPTY_ARGUMENTS);
+ condition.setImplicitThis(false);
return new TernaryExpression(
new BooleanExpression(condition),
http://git-wip-us.apache.org/repos/asf/groovy/blob/ea28001a/src/main/groovy/util/logging/Log.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/logging/Log.java b/src/main/groovy/util/logging/Log.java
index 66d3c32..39edc39 100644
--- a/src/main/groovy/util/logging/Log.java
+++ b/src/main/groovy/util/logging/Log.java
@@ -105,6 +105,7 @@ public @interface Log {
ArgumentListExpression args = new ArgumentListExpression();
args.addExpression(logLevelExpression);
MethodCallExpression condition = new MethodCallExpression(logVariable, "isLoggable", args);
+ condition.setImplicitThis(false);
return new TernaryExpression(
new BooleanExpression(condition),
http://git-wip-us.apache.org/repos/asf/groovy/blob/ea28001a/src/main/groovy/util/logging/Log4j.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/logging/Log4j.java b/src/main/groovy/util/logging/Log4j.java
index d60acd2..5a78e79 100644
--- a/src/main/groovy/util/logging/Log4j.java
+++ b/src/main/groovy/util/logging/Log4j.java
@@ -101,6 +101,7 @@ public @interface Log4j {
"is" + methodName.substring(0, 1).toUpperCase(Locale.ENGLISH) + methodName.substring(1, methodName.length()) + "Enabled",
ArgumentListExpression.EMPTY_ARGUMENTS);
}
+ condition.setImplicitThis(false);
return new TernaryExpression(
new BooleanExpression(condition),
http://git-wip-us.apache.org/repos/asf/groovy/blob/ea28001a/src/main/groovy/util/logging/Log4j2.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/logging/Log4j2.java b/src/main/groovy/util/logging/Log4j2.java
index f2685df..6aab6c5 100644
--- a/src/main/groovy/util/logging/Log4j2.java
+++ b/src/main/groovy/util/logging/Log4j2.java
@@ -95,6 +95,7 @@ public @interface Log4j2 {
logVariable,
"is" + methodName.substring(0, 1).toUpperCase(Locale.ENGLISH) + methodName.substring(1, methodName.length()) + "Enabled",
ArgumentListExpression.EMPTY_ARGUMENTS);
+ condition.setImplicitThis(false);
return new TernaryExpression(
new BooleanExpression(condition),
http://git-wip-us.apache.org/repos/asf/groovy/blob/ea28001a/src/main/groovy/util/logging/Slf4j.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/logging/Slf4j.java b/src/main/groovy/util/logging/Slf4j.java
index fad38d1..7084938 100644
--- a/src/main/groovy/util/logging/Slf4j.java
+++ b/src/main/groovy/util/logging/Slf4j.java
@@ -90,6 +90,7 @@ public @interface Slf4j {
logVariable,
"is" + methodName.substring(0, 1).toUpperCase(Locale.ENGLISH) + methodName.substring(1, methodName.length()) + "Enabled",
ArgumentListExpression.EMPTY_ARGUMENTS);
+ condition.setImplicitThis(false);
return new TernaryExpression(
new BooleanExpression(condition),
http://git-wip-us.apache.org/repos/asf/groovy/blob/ea28001a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy8069Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy8069Bug.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy8069Bug.groovy
new file mode 100644
index 0000000..38eead6
--- /dev/null
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy8069Bug.groovy
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.codehaus.groovy.classgen.asm.sc.bugs
+
+import groovy.transform.stc.StaticTypeCheckingTestCase
+import org.codehaus.groovy.classgen.asm.sc.StaticCompilationTestSupport
+
+class Groovy8069Bug extends StaticTypeCheckingTestCase implements StaticCompilationTestSupport {
+ void testComplexLogInClosure() {
+ assertScript '''
+ @groovy.util.logging.Log
+ @groovy.transform.CompileStatic
+ class Foo {
+ void bar() {
+ def callable = {
+ log.info('a' + 1)
+ }
+ callable.call()
+ }
+ }
+ new Foo().bar()
+ '''
+ }
+ void testComplexLogInClosureInStaticMethod() {
+ assertScript '''
+ @groovy.util.logging.Log
+ @groovy.transform.CompileStatic
+ class Foo {
+ static void barStatic() {
+ def callable = {
+ log.info('a' + 1)
+ }
+ callable.call()
+ }
+ }
+ Foo.barStatic()
+ '''
+ }
+}