0
public int getPos(int index) {
    if(this.hasAllTerms == false){
        throw new IllegalArgumentException("Not all terms are present");
    }
    else if(index < 0 || index > terms.size()){
        throw new ArrayIndexOutOfBoundsException("Index out of bounds!");
    }

    return minSnip.get(minSnipIndex)[index+1];
  }

}

at the else if line my Junit test fails and says null pointer exception. Where is a null pointer?

Jenny
  • 85
  • 1
  • 8
  • It doesn't just say `NullPointerException`, it gives you an exact line. – chrylis -cautiouslyoptimistic- Sep 18 '15 at 20:47
  • 1
    terms.size() this is the only thing that can give you a null pointer exception. If your terms object is Null then it will throw this exception, – Amr Sep 18 '15 at 20:50
  • terms.size() is the only place where NPE can be thrown in that else if statement. – j.swiderski Sep 18 '15 at 20:53
  • Unconnected note: if you want to throw an exception because of a condition that has nothing to do with the arguments (in this case, `this.hasAllTerms` is `false` - it has nothing to do with `index`), don't throw an `IllegalArgumentException`, but rather an `IllegalStateException`. – RealSkeptic Sep 18 '15 at 20:59

0 Answers0