Skip to content

Commit

Permalink
fix(CtRolePathElement): replace exception throwing with return null w…
Browse files Browse the repository at this point in the history
…hen element is not found in set
  • Loading branch information
nharrand committed Feb 26, 2018
1 parent 67ec78b commit 7ee9921
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/spoon/reflect/path/impl/CtRolePathElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String toString() {
return STRING + getRole().toString() + getParamString();
}

public CtElement getFromSet(Set set, String name) throws CtPathException {
private CtElement getFromSet(Set set, String name) throws CtPathException {
for (Object o: set) {
if (o instanceof CtNamedElement) {
if (((CtNamedElement) o).getSimpleName().equals(name)) {
Expand All @@ -72,7 +72,8 @@ public CtElement getFromSet(Set set, String name) throws CtPathException {
throw new CtPathException();
}
}
throw new CtPathException();
//Element is not found in set.
return null;
}

@Override
Expand Down Expand Up @@ -103,7 +104,10 @@ public Collection<CtElement> getElements(Collection<CtElement> roots) {
if (getArguments().containsKey("name")) {
String name = getArguments().get("name");
try {
matchs.add(getFromSet(roleHandler.asSet(root), name));
CtElement match = getFromSet(roleHandler.asSet(root), name);
if (match != null) {
matchs.add(match);
}
} catch (CtPathException e) {
//System.err.println("[ERROR] Element not found for name: " + name);
//No element found for name.
Expand Down

0 comments on commit 7ee9921

Please sign in to comment.