wheredevel / beanshell2

Automatically exported from code.google.com/p/beanshell2
0 stars 0 forks source link

Overriding a method which is invoked from super-constructor issues a NPE #45

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Adapted from 
http://sourceforge.net/tracker/?func=detail&aid=2081602&group_id=4075&atid=10407
5

If two classes defined in script extend each other, and you overwrite a method 
which is called from the super constructor a NullPointerException is issued.

Example code:

{{{
public class A {
   int _id;
   public A (int id) {
      setId(id);
   }
   public void setId (int id) {
      _id = id;
   }
   public int getId() { return _id; }
}
public class B extends A {
   public B (int id) {
      super (id * 3);
   }
   public void setId (int id) {
      super.setId(id * 5);
   }
}
print(new B(1).getId());
}}}

Original issue reported on code.google.com by pejob...@gmail.com on 27 Feb 2011 at 10:36

GoogleCodeExporter commented 8 years ago
test case is bsh.SourceForgeIssuesTest#sourceforge_issue_2081602

Original comment by pejob...@gmail.com on 27 Feb 2011 at 10:42

GoogleCodeExporter commented 8 years ago
Created a patch - seems a bit risky.
Need more test cases first.

Original comment by pejob...@gmail.com on 27 Feb 2011 at 10:44

Attachments:

GoogleCodeExporter commented 8 years ago
Another test case, with an abstract class.

Original comment by jarekc...@poczta.onet.pl on 31 Aug 2012 at 1:34

Attachments: