Search code examples
javanullpointerexceptionassert

NullPointerException after assert in java


The following method is a setter for a field called election_date which is of type java.util.date. It is part of a tomcat application.

Upon execution, I get a Null pointer exception on the line:

    System.out.println("ELECTION DATE: " + this.election_date.toString());

public void setElection_date(Date election_date) {

    this.election_date = election_date;
    assert (this.election_date != null);
    assert (this.election_date.toString()) != null;
    System.out.println("ELECTION DATE: " + this.election_date.toString());
}

EDIT: Please don't tell me it's being garbage collected. I may be slightly off the Balmer Peak, but not that far off.


Solution

  • In eclipse go on Run Configurations, arguments and set -ea into VM arguments

    -ea options mean enable assertions, without it the assertions are ignored