sim732 / h2database

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

TriggerAdapter: Improve error message for user error #515

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If a user extends TriggerAdapter, overrides init() but forgets to invoke 
super.init() he will get the following exception:

java.lang.NullPointerException: null
    at org.h2.tools.TriggerAdapter.wrap(TriggerAdapter.java:171) ~[h2-1.3.173.jar:1.3.173]
    at org.h2.tools.TriggerAdapter.fire(TriggerAdapter.java:145) ~[h2-1.3.173.jar:1.3.173]
    at org.h2.schema.TriggerObject.fireRow(TriggerObject.java:201) ~[h2-1.3.173.jar:1.3.173]

oldSource and newSource will both be null because init() was not invoked which 
cause the above exception. Is there any reasonable way for us to check for this 
and throw an exception reminding the user to invoke super.init()?

Alternatively, mark init() as final and have it invoke a new abstract method 
init2() which subclasses will have to implement. This will make it impossible 
to do the wrong thing.

Original issue reported on code.google.com by cow...@bbs.darktech.org on 11 Oct 2013 at 7:44