Skip to content

Handle more uncaught runtime exceptions on rekor response #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ public interface RekorResponse {
* @return an immutable {@link RekorResponse} instance
* @throws RekorParseException if the rawResponse doesn't parse directly to a single rekor entry
*/
public static RekorResponse newRekorResponse(URI entryLocation, String rawResponse)
static RekorResponse newRekorResponse(URI entryLocation, String rawResponse)
throws RekorParseException {
var type = new TypeToken<Map<String, RekorEntry>>() {}.getType();
Map<String, RekorEntry> entryMap;
try {
entryMap = GSON.get().fromJson(rawResponse, type);
} catch (JsonSyntaxException | NullPointerException | StringIndexOutOfBoundsException ex) {
} catch (JsonSyntaxException
| NullPointerException
| NumberFormatException
| StringIndexOutOfBoundsException ex) {
throw new RekorParseException("Rekor entry json could not be parsed: " + rawResponse, ex);
}
if (entryMap == null) {
Expand All @@ -71,6 +74,10 @@ public static RekorResponse newRekorResponse(URI entryLocation, String rawRespon
"Expecting a single rekor entry in response but found: " + entryMap.size());
}
var entry = entryMap.entrySet().iterator().next();
if (entry == null || entry.getKey() == null || entry.getValue() == null) {
throw new RekorParseException(
"Expecting single rekor entry but found an invalid entry: " + rawResponse);
}
return ImmutableRekorResponse.builder()
.entryLocation(entryLocation)
.raw(rawResponse)
Expand Down