From 9732a23a3b66037945a80aace9b712bd737029bd Mon Sep 17 00:00:00 2001 From: Olafxso Date: Thu, 31 Oct 2019 08:35:16 +0100 Subject: [PATCH] Update VParentBase.java check https://github.com/JFXtras/jfxtras/issues/116 --- .../java/jfxtras/icalendarfx/VParentBase.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/jfxtras-icalendarfx/src/main/java/jfxtras/icalendarfx/VParentBase.java b/jfxtras-icalendarfx/src/main/java/jfxtras/icalendarfx/VParentBase.java index 59a1d0db..92bf2944 100755 --- a/jfxtras-icalendarfx/src/main/java/jfxtras/icalendarfx/VParentBase.java +++ b/jfxtras-icalendarfx/src/main/java/jfxtras/icalendarfx/VParentBase.java @@ -331,26 +331,29 @@ protected boolean checkChild(List messages, String content, String elem MessageEffect.THROW_EXCEPTION); messages.add(message); } - final boolean isChildAlreadyPresent; - Object currentParameter = null; - try { - currentParameter = getter.invoke(this); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - } - if (currentParameter instanceof Collection) - { - isChildAlreadyPresent = ((Collection) currentParameter).contains(newChild); // TODO contains is expensive - try to find a way to avoid - } else - { - isChildAlreadyPresent = currentParameter != null; - } - if (isChildAlreadyPresent) - { - Message message = new Message(this, - newChild.getClass().getSimpleName() + " can only occur once in a calendar component. Ignoring instances beyond first.", - MessageEffect.MESSAGE_ONLY); - messages.add(message); + else // Moved to an else block, because getter could be null here + { + final boolean isChildAlreadyPresent; + Object currentParameter = null; + try { + currentParameter = getter.invoke(this); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + if (currentParameter instanceof Collection) + { + isChildAlreadyPresent = ((Collection) currentParameter).contains(newChild); // TODO contains is expensive - try to find a way to avoid + } else + { + isChildAlreadyPresent = currentParameter != null; + } + if (isChildAlreadyPresent) + { + Message message = new Message(this, + newChild.getClass().getSimpleName() + " can only occur once in a calendar component. Ignoring instances beyond first.", + MessageEffect.MESSAGE_ONLY); + messages.add(message); + } } return messages.size() == initialMessageSize; }