| 1 | package com.github.dakusui.symfonion.compat.json; | |
| 2 | ||
| 3 | import com.google.gson.JsonElement; | |
| 4 | ||
| 5 | import java.io.Serial; | |
| 6 | import java.util.Arrays; | |
| 7 | ||
| 8 | /** | |
| 9 | * An exception that indicates a path not valid in a given JSON element was accessed. | |
| 10 | */ | |
| 11 | public class JsonInvalidPathException extends CompatJsonException { | |
| 12 | /** | |
| 13 | * A serial version UID string. | |
| 14 | */ | |
| 15 | @Serial | |
| 16 | private static final long serialVersionUID = 7832147182391783569L; | |
| 17 | ||
| 18 | private final JsonElement base; | |
| 19 | ||
| 20 | private final Object[] path; | |
| 21 | ||
| 22 | private final String message; | |
| 23 | ||
| 24 | public JsonInvalidPathException(JsonElement base, Object[] path) { | |
| 25 | super(base); | |
| 26 | this.message = formatMessage(base, path); | |
| 27 | this.base = base; | |
| 28 | this.path = path; | |
| 29 | } | |
| 30 | ||
| 31 | public JsonElement getProblemCausingNode() { | |
| 32 |
1
1. getProblemCausingNode : replaced return value with null for com/github/dakusui/symfonion/compat/json/JsonInvalidPathException::getProblemCausingNode → KILLED |
return base; |
| 33 | } | |
| 34 | ||
| 35 | public Object[] getPath() { | |
| 36 |
1
1. getPath : replaced return value with null for com/github/dakusui/symfonion/compat/json/JsonInvalidPathException::getPath → KILLED |
return path; |
| 37 | } | |
| 38 | ||
| 39 | ||
| 40 | @Override | |
| 41 | public String getMessage() { | |
| 42 |
1
1. getMessage : replaced return value with "" for com/github/dakusui/symfonion/compat/json/JsonInvalidPathException::getMessage → KILLED |
return this.message; |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * Formats a message for an error that indicates a given `path` caused a problem in a JSON element `base`. | |
| 47 | * | |
| 48 | * @param base A JSON element, for which a problem is reported. | |
| 49 | * @param path A path that caused a problem in `base`. | |
| 50 | * @return A formatted message. | |
| 51 | */ | |
| 52 | protected String formatMessage(JsonElement base, Object[] path) { | |
| 53 |
1
1. formatMessage : replaced return value with "" for com/github/dakusui/symfonion/compat/json/JsonInvalidPathException::formatMessage → KILLED |
return String.format("This element (%s) doesn't have path: %s", JsonSummarizer.focusedElement(base), Arrays.toString(path)); |
| 54 | } | |
| 55 | } | |
Mutations | ||
| 32 |
1.1 |
|
| 36 |
1.1 |
|
| 42 |
1.1 |
|
| 53 |
1.1 |