@@ -41,7 +41,6 @@ public static class Options {
4141 private Long maxYamlReferences = System .getProperty ("maxYamlReferences" ) == null ? 10000000L : Long .parseLong (System .getProperty ("maxYamlReferences" ));
4242 private boolean validateYamlInput = System .getProperty ("validateYamlInput" ) == null || Boolean .parseBoolean (System .getProperty ("validateYamlInput" ));
4343 private boolean yamlCycleCheck = System .getProperty ("yamlCycleCheck" ) == null || Boolean .parseBoolean (System .getProperty ("yamlCycleCheck" ));
44- private Integer maxYamlCodePoints = System .getProperty ("maxYamlCodePoints" ) == null ? 3 * 1024 * 1024 : Integer .parseInt (System .getProperty ("maxYamlCodePoints" ));
4544 private Integer maxYamlAliasesForCollections = System .getProperty ("maxYamlAliasesForCollections" ) == null ? Integer .MAX_VALUE : Integer .parseInt (System .getProperty ("maxYamlAliasesForCollections" ));
4645 private boolean yamlAllowRecursiveKeys = System .getProperty ("yamlAllowRecursiveKeys" ) == null || Boolean .parseBoolean (System .getProperty ("yamlAllowRecursiveKeys" ));
4746
@@ -79,11 +78,7 @@ public void setYamlCycleCheck(boolean yamlCycleCheck) {
7978 }
8079
8180 public Integer getMaxYamlCodePoints () {
82- return maxYamlCodePoints ;
83- }
84-
85- public void setMaxYamlCodePoints (Integer maxYamlCodePoints ) {
86- this .maxYamlCodePoints = maxYamlCodePoints ;
81+ return System .getProperty ("maxYamlCodePoints" ) == null ? 3 * 1024 * 1024 : Integer .parseInt (System .getProperty ("maxYamlCodePoints" ));
8782 }
8883
8984 public Integer getMaxYamlAliasesForCollections () {
@@ -103,7 +98,7 @@ public void setYamlAllowRecursiveKeys(boolean yamlAllowRecursiveKeys) {
10398 }
10499 }
105100
106- private static Options options = new Options ();
101+ private static final Options options = new Options ();
107102
108103 private static final Logger LOGGER = LoggerFactory .getLogger (DeserializationUtils .class );
109104
@@ -145,7 +140,6 @@ protected void addImplicitResolvers() {
145140 addImplicitResolver (Tag .MERGE , MERGE , "<" );
146141 addImplicitResolver (Tag .NULL , NULL , "~nN\0 " );
147142 addImplicitResolver (Tag .NULL , EMPTY , null );
148- // addImplicitResolver(Tag.TIMESTAMP, TIMESTAMP, "0123456789");
149143 }
150144 }
151145
@@ -249,15 +243,15 @@ public static JsonNode readYamlTree(String contents, ParseOptions parseOptions,
249243 return Json .mapper ().convertValue (yaml .load (contents ), JsonNode .class );
250244 }
251245 try {
252- org .yaml .snakeyaml .Yaml yaml = null ;
246+ org .yaml .snakeyaml .Yaml yaml ;
253247 if (options .isValidateYamlInput ()) {
254248 yaml = buildSnakeYaml (new CustomSnakeYamlConstructor ());
255249 } else {
256250 yaml = buildSnakeYaml (new SafeConstructor (buildLoaderOptions ()));
257251 }
258252 Object o = yaml .load (contents );
259253 if (options .isValidateYamlInput ()) {
260- boolean res = exceedsLimits (o , null , new Integer ( 0 ) , new IdentityHashMap <Object , Long >(), deserializationUtilsResult );
254+ boolean res = exceedsLimits (o , null , 0 , new IdentityHashMap <>(), deserializationUtilsResult );
261255 if (res ) {
262256 LOGGER .warn ("Error converting snake-parsed yaml to JsonNode" );
263257 return getYaml30Mapper ().readTree (contents );
@@ -270,8 +264,8 @@ public static JsonNode readYamlTree(String contents, ParseOptions parseOptions,
270264 //
271265 }
272266 return Json .mapper ().convertValue (o , JsonNode .class );
273- } catch (Throwable e ) {
274- LOGGER .warn ("Error snake-parsing yaml content" , e );
267+ } catch (Exception e ) {
268+ LOGGER .warn (e . getMessage () , e );
275269 if (deserializationUtilsResult != null ) {
276270 deserializationUtilsResult .message (e .getMessage ());
277271 }
@@ -302,8 +296,7 @@ public static org.yaml.snakeyaml.Yaml buildSnakeYaml(BaseConstructor constructor
302296 }
303297 try {
304298 LoaderOptions loaderOptions = buildLoaderOptions ();
305- org .yaml .snakeyaml .Yaml yaml = new org .yaml .snakeyaml .Yaml (constructor , new Representer (new DumperOptions ()), new DumperOptions (), loaderOptions , new CustomResolver ());
306- return yaml ;
299+ return new org .yaml .snakeyaml .Yaml (constructor , new Representer (new DumperOptions ()), new DumperOptions (), loaderOptions , new CustomResolver ());
307300 } catch (Exception e ) {
308301 //
309302 LOGGER .error ("error building snakeYaml" , e );
@@ -479,8 +472,8 @@ public Object getSingleData(Class<?> type) {
479472 throw new SnakeException ("StackOverflow safe-checking yaml content (maxDepth " + options .getMaxYamlDepth () + ")" , e );
480473 } catch (DuplicateKeyException e ) {
481474 throw new SnakeException (e .getProblem ().replace ("found duplicate key" , "Duplicate field" ));
482- } catch (Throwable e ) {
483- throw new SnakeException ("Exception safe-checking yaml content (maxDepth " + options . getMaxYamlDepth () + ", maxYamlAliasesForCollections " + options .getMaxYamlAliasesForCollections () + ")" , e );
475+ } catch (Exception e ) {
476+ throw new SnakeException (e . getMessage () + "; Max code points: " + options .getMaxYamlCodePoints () , e );
484477 }
485478 }
486479 }
0 commit comments