@@ -282,9 +282,9 @@ public String get(Object key) {
282282 public String getRaw (String rawKey ) {
283283 Cursor pos = indexOf (unescape (rawKey ));
284284 if (pos .hasToken ()) {
285- assert pos .nextIf (PropertiesParser .Type .KEY );
286- assert pos .nextIf (PropertiesParser .Type .SEPARATOR );
287- assert pos .isType (PropertiesParser .Type .VALUE );
285+ validate ( pos .nextIf (PropertiesParser .Type .KEY ), pos );
286+ validate ( pos .nextIf (PropertiesParser .Type .SEPARATOR ), pos );
287+ validate ( pos .isType (PropertiesParser .Type .VALUE ), pos );
288288 return pos .raw ();
289289 } else {
290290 return null ;
@@ -343,22 +343,21 @@ public String putRaw(String rawKey, String rawValue) {
343343
344344 private void replaceValue (String key , String rawValue , String value ) {
345345 Cursor pos = indexOf (key );
346- assert pos .nextIf (PropertiesParser .Type .KEY );
347- assert pos .nextIf (PropertiesParser .Type .SEPARATOR );
348- assert pos .isType (PropertiesParser .Type .VALUE );
346+ validate ( pos .nextIf (PropertiesParser .Type .KEY ), pos );
347+ validate ( pos .nextIf (PropertiesParser .Type .SEPARATOR ), pos );
348+ validate ( pos .isType (PropertiesParser .Type .VALUE ), pos );
349349 pos .replace (new PropertiesParser .Token (PropertiesParser .Type .VALUE , rawValue , value ));
350350 }
351351
352352 // Add new tokens to the end of the list of tokens
353353 private Cursor addNewKeyValue (String rawKey , String key , String rawValue , String value ) {
354354 // Track back from end until we encounter the last VALUE token (if any)
355- PropertiesParser .Token token ;
356355 Cursor pos = last ();
357356 while (pos .isType (PropertiesParser .Type .WHITESPACE , PropertiesParser .Type .COMMENT )) {
358357 pos .prev ();
359358 }
360359 // Make sure we're either at the start or we've found a VALUE
361- assert pos .atStart () || pos .isType (PropertiesParser .Type .VALUE );
360+ validate ( pos .atStart () || pos .isType (PropertiesParser .Type .VALUE ), pos );
362361 // Add a newline whitespace token if necessary
363362 if (pos .hasToken ()) {
364363 pos .next ();
@@ -397,11 +396,11 @@ public String remove(Object key) {
397396 private void removeItem (String skey ) {
398397 setComment (skey , Collections .emptyList ());
399398 Cursor pos = indexOf (skey );
400- assert pos .isType (PropertiesParser .Type .KEY );
399+ validate ( pos .isType (PropertiesParser .Type .KEY ), pos );
401400 pos .remove ();
402- assert pos .isType (PropertiesParser .Type .SEPARATOR );
401+ validate ( pos .isType (PropertiesParser .Type .SEPARATOR ), pos );
403402 pos .remove ();
404- assert pos .isType (PropertiesParser .Type .VALUE );
403+ validate ( pos .isType (PropertiesParser .Type .VALUE ), pos );
405404 pos .remove ();
406405 if (pos .isEol ()) {
407406 pos .remove ();
@@ -555,7 +554,7 @@ private List<Integer> findPropertyCommentLines(String key) {
555554 private List <Integer > findPropertyCommentLines (Cursor pos ) {
556555 List <Integer > result = new ArrayList <>();
557556 Cursor fpos = pos .copy ();
558- assert fpos .isType (PropertiesParser .Type .KEY );
557+ validate ( fpos .isType (PropertiesParser .Type .KEY ), pos );
559558 fpos .prev ();
560559 // Skip a single preceding whitespace if it is NOT an EOL token
561560 fpos .prevIf (PropertiesParser .Token ::isWs );
@@ -796,4 +795,10 @@ private Cursor first() {
796795 private Cursor last () {
797796 return Cursor .last (tokens );
798797 }
798+
799+ private void validate (boolean ok , Cursor cursor ) {
800+ if (!ok ) {
801+ throw new IllegalStateException ("Unexpected state detected at " + cursor );
802+ }
803+ }
799804}
0 commit comments