summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-10-16 12:28:06 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2018-10-16 12:28:06 +0200
commit53b50d2015fbc22d570d7e68d09fd19c0116a585 (patch)
tree11b1daa025da5c5af88deb7bc834d30f0d2e8565 /document
parent129c1f3755b3f50d35cca7ae0e2d843777880cd1 (diff)
Rember that you did not have any constructor for this class and this parameter set.
This will enable fail fast next time instead of having an exception thrown every time.
Diffstat (limited to 'document')
-rw-r--r--document/src/main/java/com/yahoo/document/DataType.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/document/src/main/java/com/yahoo/document/DataType.java b/document/src/main/java/com/yahoo/document/DataType.java
index 3f34314f0de..dfe55f5229c 100644
--- a/document/src/main/java/com/yahoo/document/DataType.java
+++ b/document/src/main/java/com/yahoo/document/DataType.java
@@ -108,12 +108,18 @@ public abstract class DataType extends Identifiable implements Serializable, Com
if (valClass != null) {
Pair<Class<?>, Class<?>> key = new Pair<>(valClass, arg.getClass());
Constructor<?> cstr = constructorCache.get(key);
- try {
- if (cstr == null) {
- cstr = valClass.getConstructor(key.getSecond());
- constructorCache.put(key, cstr);
+ if (cstr == null) {
+ if (!constructorCache.containsKey(key)) {
+ try {
+ cstr = valClass.getConstructor(key.getSecond());
+ constructorCache.put(key, cstr);
+ } catch (NoSuchMethodException e) {
+ constructorCache.put(key, null);
+ }
}
- return (FieldValue)cstr.newInstance(arg);
+ }
+ try {
+ return cstr != null ? (FieldValue)cstr.newInstance(arg) : null;
} catch (ReflectiveOperationException e) {
// Only rethrow exceptions coming from the underlying FieldValue constructor.
if (e instanceof InvocationTargetException) {