From 72c9111b4df78c067eb5aec679f868af08db33e8 Mon Sep 17 00:00:00 2001 From: Eran Landau Date: Tue, 13 Jun 2017 23:47:13 -0700 Subject: [PATCH 1/3] Upgrade gradlew to 3.5 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c03ade10..77507023 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip From 30905a07f55fbd53737e38af7e8f327884b56665 Mon Sep 17 00:00:00 2001 From: Eran Landau Date: Thu, 6 Jul 2017 09:51:45 -0700 Subject: [PATCH 2/3] Ignore NoClassDefFoundError during class path scanning. Real issues with missing jars will be reported when Guice actually provisions an object. --- .../lifecycle/AnnotationFinder.java | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/governator-legacy/src/main/java/com/netflix/governator/lifecycle/AnnotationFinder.java b/governator-legacy/src/main/java/com/netflix/governator/lifecycle/AnnotationFinder.java index 022b2c6b..d5908802 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/lifecycle/AnnotationFinder.java +++ b/governator-legacy/src/main/java/com/netflix/governator/lifecycle/AnnotationFinder.java @@ -1,8 +1,17 @@ package com.netflix.governator.lifecycle; -import org.objectweb.asm.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static org.objectweb.asm.Type.ARRAY; +import static org.objectweb.asm.Type.BOOLEAN; +import static org.objectweb.asm.Type.BYTE; +import static org.objectweb.asm.Type.CHAR; +import static org.objectweb.asm.Type.DOUBLE; +import static org.objectweb.asm.Type.FLOAT; +import static org.objectweb.asm.Type.INT; +import static org.objectweb.asm.Type.LONG; +import static org.objectweb.asm.Type.OBJECT; +import static org.objectweb.asm.Type.SHORT; +import static org.objectweb.asm.Type.getArgumentTypes; +import static org.objectweb.asm.Type.getType; import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; @@ -13,7 +22,14 @@ import java.util.HashSet; import java.util.Set; -import static org.objectweb.asm.Type.*; +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public final class AnnotationFinder extends ClassVisitor { private static Logger log = LoggerFactory.getLogger(AnnotationFinder.class); @@ -30,7 +46,7 @@ public final class AnnotationFinder extends ClassVisitor { private ClassLoader classLoader; private Class selfClass() { - if(clazz == null) + if (clazz == null) clazz = classFromInternalName(className); return clazz; } @@ -38,9 +54,8 @@ private Class selfClass() { private Class classFromInternalName(String name) { try { return Class.forName(name.replace('/', '.'), false, classLoader); - } - catch (ClassNotFoundException e) { - throw new IllegalStateException(e); + } catch (ClassNotFoundException e) { + throw new IllegalStateException("Unable to find class " + name, e); } } @@ -97,9 +112,10 @@ public AnnotationVisitor visitAnnotation(String desc, boolean visible) { try { annotatedFields.add(selfClass().getDeclaredField(name)); break; - } - catch (NoSuchFieldException e) { - throw new IllegalStateException(e); + } catch (NoSuchFieldException e) { + throw new IllegalStateException("Error visiting field " + name, e); + } catch (NoClassDefFoundError e) { + log.info("Unable to scan field '{}' of class '{}'", name, selfClass().getName(), e.getMessage()); } } } @@ -123,15 +139,15 @@ public AnnotationVisitor visitAnnotation(String desc, boolean visible) { Type type = getType(desc); for (Type annotationType : annotationTypes) { if (annotationType.equals(type)) { - Type[] args = methodDesc == null ? new Type[0] + Type[] args = methodDesc == null + ? new Type[0] : getArgumentTypes(methodDesc); Class[] argClasses = new Class[args.length]; for (int i = 0; i < args.length; i++) { switch (args[i].getSort()) { case OBJECT: case ARRAY: - argClasses[i] = classFromInternalName(args[i] - .getInternalName()); + argClasses[i] = classFromInternalName(args[i].getInternalName()); break; case BOOLEAN: argClasses[i] = boolean.class; @@ -167,11 +183,9 @@ public AnnotationVisitor visitAnnotation(String desc, boolean visible) { else annotatedMethods.add(selfClass().getDeclaredMethod( name, argClasses)); - } - catch (NoClassDefFoundError e) { + } catch (NoClassDefFoundError e) { log.info("Unable to scan constructor of '{}' NoClassDefFoundError looking for '{}'", selfClass().getName(), e.getMessage()); - } - catch (NoSuchMethodException e) { + } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } From 3e3f43be968400d297313bbd862272cd97d64bd3 Mon Sep 17 00:00:00 2001 From: Eran Landau Date: Thu, 6 Jul 2017 13:46:42 -0700 Subject: [PATCH 3/3] Include class name in exception --- .../java/com/netflix/governator/lifecycle/AnnotationFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/governator-legacy/src/main/java/com/netflix/governator/lifecycle/AnnotationFinder.java b/governator-legacy/src/main/java/com/netflix/governator/lifecycle/AnnotationFinder.java index d5908802..7a967c24 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/lifecycle/AnnotationFinder.java +++ b/governator-legacy/src/main/java/com/netflix/governator/lifecycle/AnnotationFinder.java @@ -113,7 +113,7 @@ public AnnotationVisitor visitAnnotation(String desc, boolean visible) { annotatedFields.add(selfClass().getDeclaredField(name)); break; } catch (NoSuchFieldException e) { - throw new IllegalStateException("Error visiting field " + name, e); + throw new IllegalStateException("Error visiting field " + name + " of class " + selfClass().getName(), e); } catch (NoClassDefFoundError e) { log.info("Unable to scan field '{}' of class '{}'", name, selfClass().getName(), e.getMessage()); }