How to bypass null pointer exception?#JPF

677 views Asked by At

I am trying to run JPF and encountered a following null pointer exception.

java.lang.NullPointerException at gov.nasa.jpf.vm.ThreadInfo$StackTraceElement.createJPFStackTraceElement(ThreadInfo.java:1671)

The code that is corresponds to is:

int createJPFStackTraceElement() {
    if (ignore) {
        return MJIEnv.NULL;
    } else {
        Heap heap = vm.getHeap();
        ClassInfo ci = ClassLoaderInfo.getSystemResolvedClassInfo("java.lang.StackTraceElement");
        ElementInfo ei = heap.newObject(ci, ThreadInfo.this);

        ei.setReferenceField("clsName", heap.newString(clsName, ThreadInfo.this).getObjectRef());
        ei.setReferenceField("mthName", heap.newString(mthName, ThreadInfo.this).getObjectRef());
        ei.setReferenceField("fileName", heap.newString(fileName, ThreadInfo.this).getObjectRef());  //line 1671
        ei.setIntField("line", line);

        return ei.getObjectRef();
    }
}
1

There are 1 answers

0
Sindhoo Oad On

there are two ways

  1. your code should contain null check, so first of all it will check if value is null or not then it will be decided whether code snippet should execute or not.
  2. or you can use try catch block.