diff options
author | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2022-01-14 02:26:05 +0100 |
---|---|---|
committer | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2022-01-14 02:32:46 +0100 |
commit | 2685d37748bab76669e19a9952a3c5cbd951162a (patch) | |
tree | 3a5ab9e72b39d9cdd0b7c89d4a3a20b6238aeee8 | |
parent | 267ef9736d0ec603712962a474272218c33564a9 (diff) | |
download | lombok-2685d37748bab76669e19a9952a3c5cbd951162a.tar.gz lombok-2685d37748bab76669e19a9952a3c5cbd951162a.tar.bz2 lombok-2685d37748bab76669e19a9952a3c5cbd951162a.zip |
Fix for defaulting behaviour for lombok annotations.
What's the name of one of those bugs where you look at it and go: Wow. This can never have possibly worked?
And yet it has? An inverse heisenbug: Once observed, it has always existed, but before observing it, no problems.
Anyway, fixed. For what it's worth.
-rw-r--r-- | src/core/lombok/core/AnnotationValues.java | 17 | ||||
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleToString.java | 2 | ||||
-rw-r--r-- | src/core/lombok/javac/HandlerLibrary.java | 4 |
3 files changed, 12 insertions, 11 deletions
diff --git a/src/core/lombok/core/AnnotationValues.java b/src/core/lombok/core/AnnotationValues.java index 78bb1fb5..f5db553c 100644 --- a/src/core/lombok/core/AnnotationValues.java +++ b/src/core/lombok/core/AnnotationValues.java @@ -165,7 +165,7 @@ public class AnnotationValues<A extends Annotation> { AnnotationValue v = values.get(methodName); if (v == null) { - String[] s = getDefaultIf(methodName, String[].class, new String[0]); + String[] s = getDefaultIf(methodName, new String[0]); return Collections.unmodifiableList(Arrays.asList(s)); } @@ -175,7 +175,7 @@ public class AnnotationValues<A extends Annotation> { Object result = guess == null ? null : guessToType(guess, String.class, v, idx); if (result == null) { if (v.valueGuesses.size() == 1) { - String[] s = getDefaultIf(methodName, String[].class, new String[0]); + String[] s = getDefaultIf(methodName, new String[0]); return Collections.unmodifiableList(Arrays.asList(s)); } throw new AnnotationValueDecodeFail(v, @@ -190,28 +190,29 @@ public class AnnotationValues<A extends Annotation> { public String getAsString(String methodName) { AnnotationValue v = values.get(methodName); if (v == null || v.valueGuesses.size() != 1) { - return getDefaultIf(methodName, String.class, ""); + return getDefaultIf(methodName, ""); } Object guess = guessToType(v.valueGuesses.get(0), String.class, v, 0); if (guess instanceof String) return (String) guess; - return getDefaultIf(methodName, String.class, ""); + return getDefaultIf(methodName, ""); } public boolean getAsBoolean(String methodName) { AnnotationValue v = values.get(methodName); if (v == null || v.valueGuesses.size() != 1) { - return getDefaultIf(methodName, boolean.class, false); + return getDefaultIf(methodName, false); } Object guess = guessToType(v.valueGuesses.get(0), boolean.class, v, 0); if (guess instanceof Boolean) return ((Boolean) guess).booleanValue(); - return getDefaultIf(methodName, boolean.class, false); + return getDefaultIf(methodName, false); } - public <T> T getDefaultIf(String methodName, Class<T> type, T defaultValue) { + @SuppressWarnings("unchecked") + public <T> T getDefaultIf(String methodName, T defaultValue) { try { - return type.cast(Permit.getMethod(type, methodName).getDefaultValue()); + return (T) Permit.getMethod(type, methodName).getDefaultValue(); } catch (Exception e) { return defaultValue; } diff --git a/src/core/lombok/eclipse/handlers/HandleToString.java b/src/core/lombok/eclipse/handlers/HandleToString.java index 6beaa848..b22d162f 100644 --- a/src/core/lombok/eclipse/handlers/HandleToString.java +++ b/src/core/lombok/eclipse/handlers/HandleToString.java @@ -203,7 +203,7 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> { if (!prefix.isEmpty()) { StringLiteral px = new StringLiteral(prefix.toCharArray(), pS, pE, 0); - setGeneratedBy(px, source); + setGeneratedBy(px, source); current = new BinaryExpression(current, px, PLUS); current.sourceStart = pS; current.sourceEnd = pE; setGeneratedBy(current, source); diff --git a/src/core/lombok/javac/HandlerLibrary.java b/src/core/lombok/javac/HandlerLibrary.java index c2bf8512..d401f59d 100644 --- a/src/core/lombok/javac/HandlerLibrary.java +++ b/src/core/lombok/javac/HandlerLibrary.java @@ -104,13 +104,13 @@ public class HandlerLibrary { this.handler = handler; this.annotationClass = annotationClass; HandlerPriority hp = handler.getClass().getAnnotation(HandlerPriority.class); - this.priority = hp == null ? 0L : (((long)hp.value()) << 32) + hp.subValue(); + this.priority = hp == null ? 0L : (((long) hp.value()) << 32) + hp.subValue(); this.resolutionResetNeeded = handler.getClass().isAnnotationPresent(ResolutionResetNeeded.class); this.evenIfAlreadyHandled = handler.getClass().isAnnotationPresent(AlreadyHandledAnnotations.class); } public void handle(final JavacNode node) { - handler.handle(JavacHandlerUtil.createAnnotation(annotationClass, node), (JCAnnotation)node.get(), node); + handler.handle(JavacHandlerUtil.createAnnotation(annotationClass, node), (JCAnnotation) node.get(), node); } public long getPriority() { |