diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2020-12-27 05:36:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-27 05:36:51 +0100 |
commit | 11b6f8f97a6fde9a5f6e39f38e63cdff73742822 (patch) | |
tree | 733b5a65b754f325fa9273d11fb840a7e0002398 /src/utils/lombok | |
parent | 0532285eb8de98e9e4e3fc4131476b5f4ef2740d (diff) | |
parent | 624c8a5a52d14ba1a6b690809f9ada15f71e15f5 (diff) | |
download | lombok-11b6f8f97a6fde9a5f6e39f38e63cdff73742822.tar.gz lombok-11b6f8f97a6fde9a5f6e39f38e63cdff73742822.tar.bz2 lombok-11b6f8f97a6fde9a5f6e39f38e63cdff73742822.zip |
Merge pull request #2684 from Rawi01/npe-javadoc
Fix NullPointerException during Javadoc copy
Diffstat (limited to 'src/utils/lombok')
-rw-r--r-- | src/utils/lombok/core/FieldAugment.java | 53 | ||||
-rw-r--r-- | src/utils/lombok/javac/Javac.java | 1 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/utils/lombok/core/FieldAugment.java b/src/utils/lombok/core/FieldAugment.java index 4a32ad04..0982bcb5 100644 --- a/src/utils/lombok/core/FieldAugment.java +++ b/src/utils/lombok/core/FieldAugment.java @@ -24,6 +24,7 @@ package lombok.core; import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.HashMap; import java.util.Map; import java.util.WeakHashMap; @@ -69,6 +70,10 @@ public abstract class FieldAugment<T, F> { checkNotNull(fieldType, "fieldType"); checkNotNull(name, "name"); + if (type.isInterface()) { + return new InterfaceFieldAugment<T, F>(name, fieldType); + } + @SuppressWarnings("unchecked") F defaultValue = (F) getDefaultValue(fieldType); FieldAugment<T, F> ret = tryCreateReflectionAugment(type, fieldType, name, defaultValue); @@ -175,6 +180,54 @@ public abstract class FieldAugment<T, F> { */ public abstract F compareAndSet(T object, F expected, F value); + private static final class InterfaceFieldAugment<T, F> extends FieldAugment<T, F> { + private final String name; + private final Class<? super F> fieldType; + + private Map<Class<T>, FieldAugment<T, F>> map = new HashMap<Class<T>, FieldAugment<T,F>>(); + + private InterfaceFieldAugment(String name, Class<? super F> fieldType) { + this.name = name; + this.fieldType = fieldType; + } + + private synchronized FieldAugment<T, F> getDelegate(T object) { + @SuppressWarnings("unchecked") + Class<T> c = (Class<T>) object.getClass(); + + FieldAugment<T,F> fieldAugment = map.get(c); + if (fieldAugment == null) { + fieldAugment = augment(c, fieldType, name); + map.put(c, fieldAugment); + } + return fieldAugment; + } + + @Override public F get(T object) { + return getDelegate(object).get(object); + } + + @Override public F getAndSet(T object, F value) { + return getDelegate(object).getAndSet(object, value); + } + + @Override public F clear(T object) { + return getDelegate(object).clear(object); + } + + @Override public F compareAndClear(T object, F expected) { + return getDelegate(object).compareAndClear(object, expected); + } + + @Override public F setIfAbsent(T object, F value) { + return getDelegate(object).setIfAbsent(object, value); + } + + @Override public F compareAndSet(T object, F expected, F value) { + return getDelegate(object).compareAndSet(object, expected, value); + } + } + private static class ReflectionFieldAugment<T, F> extends FieldAugment<T, F> { private final Object lock = new Object(); private final Field field; diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java index cec43705..33bd7265 100644 --- a/src/utils/lombok/javac/Javac.java +++ b/src/utils/lombok/javac/Javac.java @@ -281,6 +281,7 @@ public class Javac { @SuppressWarnings("unchecked") public static void setDocComment(JCCompilationUnit cu, JCTree node, String javadoc) { + if (javadoc == null) return; Object dc = getDocComments(cu); if (dc instanceof Map) { ((Map<JCTree, String>) dc).put(node, javadoc); |