replace bytecode generated ExceptionUtils by a Java based version
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/55c186f4 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/55c186f4 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/55c186f4 Branch: refs/heads/parrot Commit: 55c186f429780e97c1f4afa1694d40082942d48f Parents: 0bbcf68 Author: Jochen Theodorou <[email protected]> Authored: Tue Oct 4 01:14:33 2016 +0200 Committer: Jochen Theodorou <[email protected]> Committed: Tue Oct 4 01:14:54 2016 +0200 ---------------------------------------------------------------------- build.gradle | 2 +- gradle/utils.gradle | 57 -------------------- src/main/groovy/lang/Closure.java | 3 +- src/main/groovy/lang/MetaClassImpl.java | 4 +- .../callsite/BooleanReturningMethodInvoker.java | 12 ++--- .../groovy/groovy/text/markup/BaseTemplate.java | 4 +- 6 files changed, 12 insertions(+), 70 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/55c186f4/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index fba0490..e82c4ab 100644 --- a/build.gradle +++ b/build.gradle @@ -383,7 +383,7 @@ task dgmConverter(dependsOn:compileJava) { } compileJava { - dependsOn ensureGrammars, exceptionUtils + dependsOn ensureGrammars options.fork(memoryMaximumSize: javacMain_mx) } http://git-wip-us.apache.org/repos/asf/groovy/blob/55c186f4/gradle/utils.gradle ---------------------------------------------------------------------- diff --git a/gradle/utils.gradle b/gradle/utils.gradle index b485933..6baf1c9 100644 --- a/gradle/utils.gradle +++ b/gradle/utils.gradle @@ -38,60 +38,3 @@ buildscript { classpath "org.ow2.asm:asm:$asmVersion" } } - -/** - * This tasks generates an utility class which allows sneaky throwing. - */ -task exceptionUtils { - ext.classFiles = [ - "${buildDir}/generated-classes/org/codehaus/groovy/runtime/ExceptionUtils.class", - "${compileJava.destinationDir}/org/codehaus/groovy/runtime/ExceptionUtils.class"] - outputs.files classFiles - - doLast { - ClassWriter cw = new ClassWriter(0); - MethodVisitor mv; - - cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, 'org/codehaus/groovy/runtime/ExceptionUtils', null, 'java/lang/Object', null); - - cw.visitSource('ExceptionUtils.java', null); - - mv = cw.visitMethod(ACC_PUBLIC, '<init>', '()V', null, null); - mv.visitCode(); - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitLineNumber(18, l0); - mv.visitVarInsn(ALOAD, 0); - mv.visitMethodInsn(INVOKESPECIAL, 'java/lang/Object', '<init>', '()V', false); - mv.visitInsn(RETURN); - Label l1 = new Label(); - mv.visitLabel(l1); - mv.visitLocalVariable('this', 'Lorg/codehaus/groovy/runtime/ExceptionUtils;', null, l0, l1, 0); - mv.visitMaxs(1, 1); - mv.visitEnd(); - - mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, 'sneakyThrow', '(Ljava/lang/Throwable;)V', null, null); - mv.visitCode(); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitLineNumber(20, l2); - mv.visitVarInsn(ALOAD, 0); - mv.visitInsn(ATHROW); - Label l3 = new Label(); - mv.visitLabel(l3); - mv.visitLocalVariable('e', 'Ljava/lang/Throwable;', null, l2, l3, 0); - mv.visitMaxs(1, 1); - mv.visitEnd(); - - cw.visitEnd(); - - logger.lifecycle('Generating ExceptionUtils') - classFiles.each { classFile -> - def output = file(classFile) - output.parentFile.mkdirs() - output.withOutputStream { - it << cw.toByteArray() - } - } - } -} http://git-wip-us.apache.org/repos/asf/groovy/blob/55c186f4/src/main/groovy/lang/Closure.java ---------------------------------------------------------------------- diff --git a/src/main/groovy/lang/Closure.java b/src/main/groovy/lang/Closure.java index 503a01b..e6bd284 100644 --- a/src/main/groovy/lang/Closure.java +++ b/src/main/groovy/lang/Closure.java @@ -18,6 +18,7 @@ */ package groovy.lang; +import org.apache.groovy.internal.util.UncheckedThrow; import org.codehaus.groovy.reflection.ReflectionCache; import org.codehaus.groovy.reflection.stdclasses.CachedClosureClass; import org.codehaus.groovy.runtime.*; @@ -413,7 +414,7 @@ public abstract class Closure<V> extends GroovyObjectSupport implements Cloneabl try { return (V) getMetaClass().invokeMethod(this,"doCall",args); } catch (InvokerInvocationException e) { - ExceptionUtils.sneakyThrow(e.getCause()); + UncheckedThrow.rethrow(e.getCause()); return null; // unreachable statement } catch (Exception e) { return (V) throwRuntimeException(e); http://git-wip-us.apache.org/repos/asf/groovy/blob/55c186f4/src/main/groovy/lang/MetaClassImpl.java ---------------------------------------------------------------------- diff --git a/src/main/groovy/lang/MetaClassImpl.java b/src/main/groovy/lang/MetaClassImpl.java index ac9d767..d7d8d9b 100644 --- a/src/main/groovy/lang/MetaClassImpl.java +++ b/src/main/groovy/lang/MetaClassImpl.java @@ -18,6 +18,7 @@ */ package groovy.lang; +import org.apache.groovy.internal.util.UncheckedThrow; import org.codehaus.groovy.GroovyBugError; import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.classgen.asm.BytecodeHelper; @@ -34,7 +35,6 @@ import org.codehaus.groovy.reflection.ReflectionCache; import org.codehaus.groovy.runtime.ConvertedClosure; import org.codehaus.groovy.runtime.CurriedClosure; import org.codehaus.groovy.runtime.DefaultGroovyMethods; -import org.codehaus.groovy.runtime.ExceptionUtils; import org.codehaus.groovy.runtime.GeneratedClosure; import org.codehaus.groovy.runtime.GroovyCategorySupport; import org.codehaus.groovy.runtime.InvokerHelper; @@ -3295,7 +3295,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass { addProperties(); } catch (Throwable e) { if (!AndroidSupport.isRunningAndroid()) { - ExceptionUtils.sneakyThrow(e); + UncheckedThrow.rethrow(e); } // Introspection failure... // May happen in Android http://git-wip-us.apache.org/repos/asf/groovy/blob/55c186f4/src/main/org/codehaus/groovy/runtime/callsite/BooleanReturningMethodInvoker.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/runtime/callsite/BooleanReturningMethodInvoker.java b/src/main/org/codehaus/groovy/runtime/callsite/BooleanReturningMethodInvoker.java index 4d1b0a0..428b8ce 100644 --- a/src/main/org/codehaus/groovy/runtime/callsite/BooleanReturningMethodInvoker.java +++ b/src/main/org/codehaus/groovy/runtime/callsite/BooleanReturningMethodInvoker.java @@ -18,7 +18,7 @@ */ package org.codehaus.groovy.runtime.callsite; -import org.codehaus.groovy.runtime.ExceptionUtils; +import org.apache.groovy.internal.util.UncheckedThrow; /** * Helper class for internal use only. This allows to call a given method and @@ -51,9 +51,8 @@ public class BooleanReturningMethodInvoker { Object ret = csa.array[0].call(receiver, args); return convertToBoolean(ret); } catch (Throwable t) { - // ExceptionUtils is a bytecode generated helper class - // to allow throwing checked exceptions without declaring a throws - ExceptionUtils.sneakyThrow(t); + // UncheckedThrow allows throwing checked exceptions without declaring a throws + UncheckedThrow.rethrow(t); return false; } } @@ -68,9 +67,8 @@ public class BooleanReturningMethodInvoker { try { arg = csa.array[1].call(arg, CallSiteArray.NOPARAM); } catch (Throwable t) { - // ExceptionUtils is a bytecode generated helper class - // to allow throwing checked exceptions without declaring a throws - ExceptionUtils.sneakyThrow(t); + // UncheckedThrow allows throwing checked exceptions without declaring a throws + UncheckedThrow.rethrow(t); } return ((Boolean) arg).booleanValue(); } http://git-wip-us.apache.org/repos/asf/groovy/blob/55c186f4/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java ---------------------------------------------------------------------- diff --git a/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java b/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java index fa1301c..d9b89cc 100644 --- a/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java +++ b/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java @@ -21,8 +21,8 @@ package groovy.text.markup; import groovy.lang.Closure; import groovy.lang.Writable; import groovy.text.Template; +import org.apache.groovy.internal.util.UncheckedThrow; import org.codehaus.groovy.control.io.NullWriter; -import org.codehaus.groovy.runtime.ExceptionUtils; import org.codehaus.groovy.runtime.ResourceGroovyMethods; import java.io.IOException; @@ -518,7 +518,7 @@ public abstract class BaseTemplate implements Writable { try { writeTo(wrt); } catch (IOException e) { - ExceptionUtils.sneakyThrow(e); + UncheckedThrow.rethrow(e); } return wrt.toString(); }
