cancel
Showing results for 
Search instead for 
Did you mean: 

Module Null pointer exception

Former Member
0 Kudos

Hi,

I am having a problem with my module written for Enhancing functionality of file adapter.My module validates a input file for a particular record presence and if that record is present it would be processed normally by XI system.

But in case, if the input file doesn't contain the particular record the module is supposed to throw an exception and process shuld terminate.In this case XI shuldn't process the input file.

But in second case(File not containing the record) I am getting Null pointer exception in adapter monitor.Unable to see any message in auditlog since input file is not being read by file adapter.

My code is like this:

public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)

throws ModuleException {

// TODO Auto-generated method stub

//Declarations

Message mes = null;

XMLPayload xmlData = null;

DocumentBuilderFactory docBuilderFactory = null;

DocumentBuilder docBuilder = null;

Document doc = null;

AuditMessageKey amk = null;

boolean flag = false;

// Fetch the Message Data from Module Data

mes = (Message) inputModuleData.getPrincipalData();

// For Audit Log Fetch the Audit Message key from the message.

amk = new AuditMessageKey(mes.getMessageId(), AuditDirection.OUTBOUND);

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Amex Validation Module called");

xmlData = mes.getDocument();

InputStream instr = xmlData.getInputStream();

docBuilderFactory = DocumentBuilderFactory.newInstance();

try {

docBuilder = docBuilderFactory.newDocumentBuilder();

} catch (ParserConfigurationException e) {

// TODO Auto-generated catch block

Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR, "Document Builder Factory not generated Properly");

}

try {

doc = docBuilder.parse(instr);

} catch (SAXException e1) {

// TODO Auto-generated catch block

Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR, "Document Not generated Properly, SAX Exception called, May Data contains Error");

} catch (IOException e1) {

// TODO Auto-generated catch block

Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR, "Document Not generated Properly, Input/Output Error");

}

NodeList record = doc.getElementsByTagName("Recordset");

for (int k = 0; k < record.getLength(); k++) {

Node recordnode = record.item(k);

NodeList list_rec = recordnode.getChildNodes();

for (int l = 0; l < list_rec.getLength(); l++) {

String headnodename =

list_rec.item(l).getNodeName().toString();

if (headnodename.equals("itemType9")) {

flag = true;

}

}

}

if (flag == true)

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Record Type 9 present in the file, Successfully Processed");

else{

Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR, "Record Type 9 not present in the file, Not process further");

//throw exception

ModuleException e = new ModuleException();

throw(e);

}

return inputModuleData;

}

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Abdul,

Please can you go through the thread

Do let us know if it helps.

Regards,

Abhy

Message was edited by: Abhy Thomas

Former Member
0 Kudos

Are you sure the following statement is going to work always ?

NodeList record = doc.getElementsByTagName("Recordset");

In case there are no nodes by the name <b>Recordset</b>, the very next block of code will throw a NullPointerException at the line

for (int k = 0; k < record.getLength(); k++) {

because, if record is null, record.getLength() would not work and throw NLP.

Former Member
0 Kudos

Hi,

Please can you read File adapter SAP Note: 821267.

It has Q-31 on Blank File.

Empty File Processing

Q: How does the File Adapter handle empty files and messages with a zero-sized payload?

A: Empty files in the sender adapter will not trigger the creation of a message. If an empty message is sent to a receiver channel, no output file will be created.

Regards

Vijaya

Message was edited by: vijaya kumari

Former Member
0 Kudos

Hi Vijaya,

I am not having problem with blank file.I am facing problem in case of a flat file containing some records.

I am validating the file on the basis of a aparticular record.I mean when i try to run a file containg some records but not having the particular record whcih i am checking for in my code,file adpater is throwing Null pointer exception.F.Y.I

2006-07-12 02:11:20 MST: Retry interval started. Length: 20.000 s

- 2006-07-12 02:11:20 MST: Error: java.lang.NullPointerException

- 2006-07-12 02:11:20 MST: An unknown error occured.

- 2006-07-12 02:11:20 MST: Processing started

- 2006-07-12 02:11:13 MST: Error: java.lang.NullPointerException