@@ -282,9 +282,9 @@ public String get(Object key) {
282
282
public String getRaw (String rawKey ) {
283
283
Cursor pos = indexOf (unescape (rawKey ));
284
284
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 );
288
288
return pos .raw ();
289
289
} else {
290
290
return null ;
@@ -343,22 +343,21 @@ public String putRaw(String rawKey, String rawValue) {
343
343
344
344
private void replaceValue (String key , String rawValue , String value ) {
345
345
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 );
349
349
pos .replace (new PropertiesParser .Token (PropertiesParser .Type .VALUE , rawValue , value ));
350
350
}
351
351
352
352
// Add new tokens to the end of the list of tokens
353
353
private Cursor addNewKeyValue (String rawKey , String key , String rawValue , String value ) {
354
354
// Track back from end until we encounter the last VALUE token (if any)
355
- PropertiesParser .Token token ;
356
355
Cursor pos = last ();
357
356
while (pos .isType (PropertiesParser .Type .WHITESPACE , PropertiesParser .Type .COMMENT )) {
358
357
pos .prev ();
359
358
}
360
359
// 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 );
362
361
// Add a newline whitespace token if necessary
363
362
if (pos .hasToken ()) {
364
363
pos .next ();
@@ -397,11 +396,11 @@ public String remove(Object key) {
397
396
private void removeItem (String skey ) {
398
397
setComment (skey , Collections .emptyList ());
399
398
Cursor pos = indexOf (skey );
400
- assert pos .isType (PropertiesParser .Type .KEY );
399
+ validate ( pos .isType (PropertiesParser .Type .KEY ), pos );
401
400
pos .remove ();
402
- assert pos .isType (PropertiesParser .Type .SEPARATOR );
401
+ validate ( pos .isType (PropertiesParser .Type .SEPARATOR ), pos );
403
402
pos .remove ();
404
- assert pos .isType (PropertiesParser .Type .VALUE );
403
+ validate ( pos .isType (PropertiesParser .Type .VALUE ), pos );
405
404
pos .remove ();
406
405
if (pos .isEol ()) {
407
406
pos .remove ();
@@ -555,7 +554,7 @@ private List<Integer> findPropertyCommentLines(String key) {
555
554
private List <Integer > findPropertyCommentLines (Cursor pos ) {
556
555
List <Integer > result = new ArrayList <>();
557
556
Cursor fpos = pos .copy ();
558
- assert fpos .isType (PropertiesParser .Type .KEY );
557
+ validate ( fpos .isType (PropertiesParser .Type .KEY ), pos );
559
558
fpos .prev ();
560
559
// Skip a single preceding whitespace if it is NOT an EOL token
561
560
fpos .prevIf (PropertiesParser .Token ::isWs );
@@ -796,4 +795,10 @@ private Cursor first() {
796
795
private Cursor last () {
797
796
return Cursor .last (tokens );
798
797
}
798
+
799
+ private void validate (boolean ok , Cursor cursor ) {
800
+ if (!ok ) {
801
+ throw new IllegalStateException ("Unexpected state detected at " + cursor );
802
+ }
803
+ }
799
804
}
0 commit comments