Best course of action for impossible errors?

Not sure on what the best course of action here is.

I have been investigating bugs 2817148 and 2817145

NPE in BasicLogger.write().

The user ends a game, but a logging is still active. He says, ‘Yes, write the logfile’, so BasicLogger.write() gets called but magically, the outputFile variable is null and you get an NPE.

I just can’t see it.

I can program defensively and check the outputFile is null (though it should be impossible) and ask the user again to select a file, but this does not solve the probem of why this is happening.

Alternatively, I add extensive debug messages to the errorLog and raise an IllegalStateException when this situation occurs and try and work out why it is happening?

I’m going to go for alternative 2 and try and get to the bottom of it.

B.

Thus spake “Brent Easton”:

I would go with option 2 also. Programming defensively is just a bandage
when a precondition is being violated.

I’ve been thinking about this recently due to all of the places where
we test for nulls. I wish we had some way to specify that a method
should not be called with a null, so that if it was called with input
which could be null then it just wouldn’t compile. (Also, complementary
ways to specify that certain variables cannot have null as a value and
that certain methods cannot return a null.)

There’s going to be a @NonNull annotation in Java 7 (and there’s already
a JAR for this for backwards compatiblity, so we could use it already),
along with some checkers which tell you about non-null correctness. E.g.:

jastadd.org/jastadd-tutorial-exa … s-for-java
homepages.mcs.vuw.ac.nz/~djp/JACK/
groups.csail.mit.edu/pag/jsr308/

I think annotating class members, return types, and method prarameters
which should never be null is a good idea and would (1) let us remove
tons of boilerplate “foo != null” checks, (2) help us find problems like
the one you’re having, and (3) help us not create any more problems of
this kind.

This would be kind of a big job, but right now it’s one of the things
which are a huge mess, in that we haven’t documented when nulls are
acceptable return or parameter values, and we lose a lot of time to it
as a result—both when we’re coding and we have to spend time figuring
out whether something could be a null, and when we get bug reports because
we failed to take into account that something could be a null.

Thoughts?


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Yes, this sounds good, as long we can get it working with Eclipse.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)