Menu

#9 NullPointerException in PduFactory.java

open
nobody
None
5
2012-10-30
2010-01-30
No

in method

public Pdu createPdu(java.nio.ByteBuffer buff)

    Pdu aPdu = null;

    switch (pduTypeEnum) {
        ...
        case FIRE:
            aPdu = new FirePdu();
            break;
        ...
        default:
            System.out.print("PDU not implemented. Type = " + pduType + "\n");
            if (pduTypeEnum != null) {
                System.out.print("PDU not implemented name is: " + pduTypeEnum.getDescription());
            }
            System.out.println();

    }   // end switch

    try {
        aPdu.unmarshal(buff);
    } catch (Exception exc) {
        //System.err.println("Could not unmarshal Pdu: " + exc.getMessage());
        aPdu = null;
    }

Within the default case the variable aPdu is not initialized and therefore a NullPointerException is thrown when trying to unmarshal in the following try-catch statement.

Discussion