Skip to content

Commit

Permalink
Update VParentBase.java
Browse files Browse the repository at this point in the history
check #116
  • Loading branch information
Olafxso authored Oct 31, 2019
1 parent f60f56f commit 9732a23
Showing 1 changed file with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,26 +331,29 @@ protected boolean checkChild(List<Message> 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;
}
Expand Down

0 comments on commit 9732a23

Please sign in to comment.