aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/MemberInitializationsAfterExplicitConstructorCalls.java
diff options
context:
space:
mode:
authorwisberg <wisberg>2002-12-16 18:51:06 +0000
committerwisberg <wisberg>2002-12-16 18:51:06 +0000
commit144143c2970a1e874d74cdbd0f8c622d4282a3c3 (patch)
treeb12383d3d9e76c7e1f25f7fbec83051ef17f81fb /tests/new/MemberInitializationsAfterExplicitConstructorCalls.java
parentfafae443719b26159ab2d7dac1c9b46b5e00b671 (diff)
downloadaspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz
aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip
initial version
Diffstat (limited to 'tests/new/MemberInitializationsAfterExplicitConstructorCalls.java')
-rw-r--r--tests/new/MemberInitializationsAfterExplicitConstructorCalls.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/new/MemberInitializationsAfterExplicitConstructorCalls.java b/tests/new/MemberInitializationsAfterExplicitConstructorCalls.java
new file mode 100644
index 000000000..107a4d974
--- /dev/null
+++ b/tests/new/MemberInitializationsAfterExplicitConstructorCalls.java
@@ -0,0 +1,42 @@
+
+import org.aspectj.testing.Tester;
+
+/**
+ * PR#476:
+ * Member initializations are run after explicit
+ * constructor calls ("this()") when they should be run beforehand.
+ * The following program would produce a NullPointerException because
+ * 'member' is set to null *after* the explicit constructor sets it
+ * to "correctValue".
+ */
+public class MemberInitializationsAfterExplicitConstructorCalls {
+ public static void main(String[] args) {
+ // passes - no constructor call to this
+ ThisCall thisCall = new ThisCall("foo");
+ thisCall.go();
+ // fails - constructor call to this
+ thisCall = new ThisCall();
+ thisCall.go();
+ }
+
+ static class ThisCall {
+ String init = "INIT";
+ String member = null;
+ /** set init and member to input */
+ ThisCall(String input) {
+ this.init = input;
+ this.member = input;
+ }
+ ThisCall() {
+ this("correctValue");
+ Tester.check(!"INIT".equals(init), "String constructor: !\"INIT\".equals(init)");
+ Tester.check(null != member, "String constructor: null != member");
+ // get NPE here if using member
+ }
+ void go() {
+ Tester.check(!"INIT".equals(init), "instance method: !\"INIT\".equals(init)");
+ Tester.check(null != member, "instance method: null != member");
+ // get NPE here if using member
+ }
+ }
+}