From 53b50d2015fbc22d570d7e68d09fd19c0116a585 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 16 Oct 2018 12:28:06 +0200 Subject: 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. --- document/src/main/java/com/yahoo/document/DataType.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'document') 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> 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) { -- cgit v1.2.3