Skip to content

Commit

Permalink
Fix NullPointer on invalid settings
Browse files Browse the repository at this point in the history
Settings having only a single Type caused a NullPointer when
printing the allowed types.

Improves gitlab4j#818
  • Loading branch information
tschwery committed Mar 16, 2022
1 parent ee4408a commit e32ac38
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/org/gitlab4j/api/models/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -1199,9 +1199,14 @@ public final void validate(Object value) throws GitLabApiException {
return;
}

StringBuilder shouldBe = new StringBuilder(types[0].getSimpleName());
for (int i = 1; i < types.length; i++) {
shouldBe.append(" | ").append(types[i].getSimpleName());
StringBuilder shouldBe;
if (type != null) {
shouldBe = new StringBuilder(type.getSimpleName());
} else {
shouldBe = new StringBuilder(types[0].getSimpleName());
for (int i = 1; i < types.length; i++) {
shouldBe.append(" | ").append(types[i].getSimpleName());
}
}

String errorMsg = String.format("'%s' value is of incorrect type, is %s, should be %s",
Expand Down

0 comments on commit e32ac38

Please sign in to comment.