keith-turner commented on code in PR #5465: URL: https://github.com/apache/accumulo/pull/5465#discussion_r2037623359
########## core/src/main/java/org/apache/accumulo/core/data/LoadPlan.java: ########## @@ -325,15 +329,47 @@ public String toJson() { return gson.toJson(new JsonAll(destinations)); } + private static final Set<String> EXPECTED_FIELDS = Arrays + .stream(JsonAll.class.getDeclaredFields()).map(Field::getName).collect(Collectors.toSet()); + private static final Set<String> EXPECTED_DEST_FIELDS = + Arrays.stream(JsonDestination.class.getDeclaredFields()).map(Field::getName) + .collect(Collectors.toSet()); + /** * Deserializes json to a load plan. * * @param json produced by {@link #toJson()} + * @throws IllegalArgumentException when illegal json is given or legal json that does not follow + * the load plan schema is given. The minimal acceptable json is + * {@code {"destinations":[]}}. */ public static LoadPlan fromJson(String json) { - var dests = gson.fromJson(json, JsonAll.class).destinations.stream() - .map(JsonDestination::toDestination).collect(Collectors.toUnmodifiableList()); - return new LoadPlan(dests); + try { + // https://github.com/google/gson/issues/188 Gson does not support failing when extra fields + // are present. This is custom code to check for extra fields. + var jsonObj = gson.fromJson(json, JsonObject.class); + Preconditions.checkArgument(jsonObj != null, "Empty json is not accepted."); Review Comment: The intent of that code as to handle empty string which causes gson to return null. Changed the handling for this to be more direct in 053c978. Also realized that direct handling for the passed json being null was needed and add that also. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org