summaryrefslogtreecommitdiff
path: root/chapter14/src/test/java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-10-11 12:22:21 -0700
committerCliff Click <cliffc@acm.org>2024-10-12 11:39:00 -0700
commit96d028ce004f5b4581997fd1d1a0ccfa87d67ea3 (patch)
treee2a33abe9c4c0e3ada4d733bbc109f705ea31da8 /chapter14/src/test/java
parent4dd51b1b14dfffb9f0ee184413f45285cc867fda (diff)
downloadSimple-96d028ce004f5b4581997fd1d1a0ccfa87d67ea3.tar.gz
Simple-96d028ce004f5b4581997fd1d1a0ccfa87d67ea3.zip
Fix a null-check bug
Diffstat (limited to 'chapter14/src/test/java')
-rw-r--r--chapter14/src/test/java/com/seaofnodes/simple/Chapter13Test.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter13Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter13Test.java
index 62191459..0edb2d51 100644
--- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter13Test.java
+++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter13Test.java
@@ -163,4 +163,22 @@ return new S1.s=new S2;
StopNode stop = parser.parse().iterate(false);
assertEquals("return new S1;", stop.toString());
}
+
+ @Test
+ public void testcheckNull() {
+ Parser parser = new Parser(
+"""
+struct I {int i;}
+struct P {I pi;}
+P p1 = new P;
+P p2 = new P;
+p2.pi = new I;
+p2.pi.i = 2;
+if (arg) p1 = new P;
+return p1.pi.i + 1;
+""");
+ try { parser.parse(false).iterate(); fail(); }
+ catch( Exception e ) { assertEquals("Might be null accessing 'i'",e.getMessage()); }
+ }
+
}