function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
federico_vela_pfederico_vela_p 

Partner Portal Tool Kit - Null Pointer Exception on Create - Could be Axis Bug ?

Hello,

Using the "create" operation, I am getting a NullPointerException when invoking the AppExchange server.

This code was previously written by someone else and was working fine, I added some copy/paste code, changed the things i needed to be different, but I am now getting this error.

Environment:
Win 2k
NetBeans 5.5b
Axis 1.1 1544 December 9 2004
Java 1.4.2

Here is the code:

public int createClassMembers(SforceManager mgr, List contactIdList, String classId){

//For Student_Assessment__c objects
ArrayList studentAssessmentObjects = new ArrayList();
ArrayList studentAssessmentFields;
List saveResultStudentAssessments = new ArrayList();

//For Contact objects
ArrayList classMemberObjects = new ArrayList();
ArrayList mElem = new ArrayList();
List saveResultClassMember = new ArrayList();

//loop through all contacts
for(int i=0;contactIdList.size()> i; i++){

MessageElement [] fields;
String contactId = contactIdList.get(i).toString();

//create contact: this was here before and works fine
SObject sObj = new SObject();
sObj.setType(classMemberObjectName);
mElem.add(new MessageElement(new QName("Class__c"),classId));
mElem.add(new MessageElement(new QName("Contact__c"),contactId));
Iterator fIte = mElem.iterator();
fields = new MessageElement[mElem.size()];
int index = 0;
while (fIte.hasNext()){
fields[index] = (MessageElement) fIte.next();
index ++;
}
sObj.set_any(fields);
classMemberObjects.add(i,sObj);

// now create two student assessment objects for each student
sObj = new SObject();
sObj.setType(studentAssessmentObjectName);
studentAssessmentFields = new ArrayList();
studentAssessmentFields.add(new MessageElement(new QName("Assessment_M1__c")," "));
studentAssessmentFields.add(new MessageElement(new QName("Assessment_M2__c")," "));
studentAssessmentFields.add(new MessageElement(new QName("Assessment_M3__c")," "));
studentAssessmentFields.add(new MessageElement(new QName("Assessment_M4__c")," "));
studentAssessmentFields.add(new MessageElement(new QName("Assessment_M5__c")," "));
studentAssessmentFields.add(new MessageElement(new QName("Class__c"),classId));
studentAssessmentFields.add(new MessageElement(new QName("Student__c"),contactId));
studentAssessmentFields.add(new MessageElement(new QName("Assessment_Type__c"),saTypeMidtermName));
fIte = mElem.iterator();
fields = new MessageElement[studentAssessmentFields.size()];
index = 0;
while (fIte.hasNext()){
fields[index] = (MessageElement) fIte.next();
index ++;
}
sObj.set_any(fields);
studentAssessmentObjects.add(sObj);

sObj = new SObject();
sObj.setType(studentAssessmentObjectName);
studentAssessmentFields = new ArrayList();
studentAssessmentFields.add(new MessageElement(new QName("Assessment_M1__c")," "));
studentAssessmentFields.add(new MessageElement(new QName("Assessment_M2__c")," "));
studentAssessmentFields.add(new MessageElement(new QName("Assessment_M3__c")," "));
studentAssessmentFields.add(new MessageElement(new QName("Assessment_M4__c")," "));
studentAssessmentFields.add(new MessageElement(new QName("Assessment_M5__c")," "));
studentAssessmentFields.add(new MessageElement(new QName("Class__c"),classId));
studentAssessmentFields.add(new MessageElement(new QName("Student__c"),contactId));
studentAssessmentFields.add(new MessageElement(new QName("Assessment_Type__c"),saTypeFinalName));
fIte = mElem.iterator();
fields = new MessageElement[studentAssessmentFields.size()];
index = 0;
while (fIte.hasNext()){
fields[index] = (MessageElement) fIte.next();
index ++;
}
sObj.set_any(fields);
studentAssessmentObjects.add(sObj);

//**** END creation of student assessments
}

log.debug("CREATING CLASS MEMBERS NOW...");
saveResultClassMember = mgr.createEntities(classMemberObjects);
int saveCounter = 0;
for(int i=0; i
SaveResult result = (SaveResult) saveResultClassMember.get(i);
if(result.isSuccess() == true){
saveCounter++;
}
}
log.debug("CREATed "+saveCounter+" CLASS MEMBERS NOW...");


log.debug("WILL TRY TO CREATE "+studentAssessmentObjects.size()+" STUDENT ASSESSMENTS NOW...");

//Next line Throws NullPointerException
saveResultStudentAssessments = mgr.createEntities(studentAssessmentObjects);
Iterator iteSASaveResults = saveResultStudentAssessments.iterator();
int saCount =0;
while(iteSASaveResults.hasNext()){
SaveResult result = (SaveResult) iteSASaveResults.next();
if(result.isSuccess() == true){
saCount++;
}
}
log.debug("CREATED "+saCount+" STUDENT ASSESSMENTS");




Here is the chopped up exception:


132657 [http-8084-Processor22] DEBUG SforceManager - WILL TRY TO CREATE 2 STUDENT ASSESSMENTS NOW...
132657 [http-8084-Processor22] INFO SforceManager - elvis@littlekidsrock.org: Broke object[] of size 2 into 1 chunks.
283016 [http-8084-Processor22] ERROR org.apache.axis.encoding.ser.BeanSerializer - Exception:
java.lang.NullPointerException
at org.apache.axis.encoding.ser.BeanSerializer.serialize(BeanSerializer.java:255)
at org.apache.axis.encoding.SerializationContextImpl.serializeActual(SerializationContextImpl.java:1255)
... deleted for brevity
at org.apache.axis.client.Call.invoke(Call.java:1691)
at com.sforce.soap.partner.SoapBindingStub.create(SoapBindingStub.java:1325)
at com.sforce.SforceManager.createEntities(SforceManager.java:537)
at com.sforce.TPSforceManager.createClassMembers(TPSforceManager.java:138) <-- Source code above is in this Class
at com.sforce.struts.action.NewStudentSaveAction.execute(NewStudentSaveAction.java:279)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
... deleted for brevity
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:534)
283032 [http-8084-Processor22] FATAL SforceManager - ; nested exception is:
java.io.IOException: java.lang.NullPointerException
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.io.IOException: java.lang.NullPointerException
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace: java.io.IOException: java.lang.NullPointerException
at org.apache.axis.encoding.ser.BeanSerializer.serialize(BeanSerializer.java:265)
... deleted for brevity
at com.sforce.soap.partner.SoapBindingStub.create(SoapBindingStub.java:1325)
at com.sforce.SforceManager.createEntities(SforceManager.java:537)
at com.sforce.TPSforceManager.createClassMembers(TPSforceManager.java:138)
at com.sforce.struts.action.NewStudentSaveAction.execute(NewStudentSaveAction.java:279)
... deleted for brevity
... 41 more
283110 [http-8084-Processor22] INFO SforceManager - elvis@littlekidsrock.org: Updated chunk... 1 of 1 (rate=1196.0)
283110 [http-8084-Processor22] INFO SforceManager - elvis@littlekidsrock.org: Done, results count is 0
283110 [http-8084-Processor22] DEBUG SforceManager - CREATED 0 STUDENT ASSESSMENTS


I would sure appreciate some help with this.

Thank you very much.
--
Federico Vela
Product Specialist
fvela@paysett.com
+ (57) 1 - 622 - 5352
+ (57) 1 - 622 - 5268
MSN Messenger : fvela@paysett.com
ICQ Number : 210 521 656

Message Edited by federico_vela_p on 07-11-2006 02:56 PM

SuperfellSuperfell
I think you'll need to look in the beanSerializer code when it NPEs, to find out what object/field its NPEing on.
federico_vela_pfederico_vela_p
Dear Simon,

So it must be a NPE on one of the fields of my object?

My class_Members__c objects get set correctly. the problem is with the student_assesssment__c

, AFAIK, I am providing all the fields that are necessary for the object, all fields i am either explicitly setting or they have defaultedOnCreate = true (See list below)

That is why I'm thinking its a NPE on a soap property like a header or such thing.

However, right above the error I am successfully inserting a Class_Members__c object so i have doubts about that also...

Any other ideas ?


Simon, thank you very much for your time and consideration.

fEderico Vela

Looking into object Student_Assessment__c
    dsor.isActivateable() = false
    dsor.isCustom() = true
    dsor.isDeletable() = true
    dsor.isLayoutable() = true
    dsor.isQueryable() = true
    dsor.isReplicateable() = true
    dsor.isRetrieveable() = true
    dsor.isSearchable() = true
    dsor.isUndeletable() = false
    dsor.isUpdateable() = true

///////// fields 0 - 6  have     field.isDefaultedOnCreate() = true so i shouldnt have to set them.

Field 0 is Id
    field.isAutoNumber() = false
    field.isCreateable() = false
    field.isDefaultedOnCreate() = true
    field.isNillable() = false
Field 1 is Name
    field.isAutoNumber() = true
    field.isCreateable() = false
    field.isDefaultedOnCreate() = true
    field.isNillable() = false
Field 2 is CreatedDate
    field.isAutoNumber() = false
    field.isCreateable() = false
    field.isDefaultedOnCreate() = true
    field.isNillable() = false
Field 3 is CreatedById
    field.isAutoNumber() = false
    field.isCreateable() = false
    field.isDefaultedOnCreate() = true
    field.isNillable() = false
Field 4 is LastModifiedDate
    field.isAutoNumber() = false
    field.isCreateable() = false
    field.isDefaultedOnCreate() = true
    field.isNillable() = false
Field 5 is LastModifiedById
    field.isAutoNumber() = false
    field.isCreateable() = false
    field.isDefaultedOnCreate() = true
    field.isNillable() = false
Field 6 is SystemModstamp
    field.isAutoNumber() = false
    field.isCreateable() = false
    field.isDefaultedOnCreate() = true
    field.isNillable() = false

/////////////////All fields below i am setting explicitly

Field 7 is Assessment_M2__c
    field.isAutoNumber() = false
    field.isCreateable() = true
    field.isDefaultedOnCreate() = false
    field.isNillable() = true
Field 8 is Assessment_M3__c
    field.isAutoNumber() = false
    field.isCreateable() = true
    field.isDefaultedOnCreate() = false
    field.isNillable() = true

///////////// this field is calculated

Field 9 is Aggregate_Assessment_Score__c
    field.isAutoNumber() = false
    field.isCalculated() = true
    field.isCreateable() = false
    field.isDefaultedOnCreate() = false
    field.isNillable() = true


/////////////////All fields below i am setting explicitly


Field 10 is Assessment_M4__c
    field.isAutoNumber() = false
    field.isCreateable() = true
    field.isDefaultedOnCreate() = false
    field.isNillable() = true
Field 11 is Assessment_M5__c
    field.isAutoNumber() = false
    field.isCreateable() = true
    field.isDefaultedOnCreate() = false
    field.isNillable() = true
Field 12 is Class__c
    field.isAutoNumber() = false
    field.isCreateable() = true
    field.isDefaultedOnCreate() = false
    field.isNillable() = true
Field 13 is Assessment_M1__c
    field.isAutoNumber() = false
    field.isCreateable() = true
    field.isDefaultedOnCreate() = false
    field.isNillable() = true
Field 14 is Assessment_Type__c
    field.isAutoNumber() = false
    field.isCreateable() = true
    field.isDefaultedOnCreate() = false
    field.isNillable() = true
Field 15 is Student__c
    field.isAutoNumber() = false
    field.isCreateable() = true
    field.isDefaultedOnCreate() = false
    field.isNillable() = false

Message Edited by federico_vela_p on 07-12-2006 01:12 PM

SuperfellSuperfell
Rather than guessing, use a debugger to find out.
federico_vela_pfederico_vela_p
Yes, of course i'm using a debugger, the problem is that this portal was built with Axis 1.1 and i only get a .jar with .class files. so i cannot set breakpoints in the serializer.

I tried installing the axis 1.1 sourcecode and compile it... but its too old and its dependencies are also too old and could not compile it.

Any other thoughts?
SuperfellSuperfell
In eclipse at least you can use the jar and point it at the source code separately, its probably good enough to tell you whats going on.
federico_vela_pfederico_vela_p
So, most definetly, it is a field in my object that causes the NPE?
SuperfellSuperfell
No idea. you're getting an NPE from axis trying to build the request, this is not coming from the Api server, which implies to me that something in your objects is null that axis is not expecting it to be.
federico_vela_pfederico_vela_p
Thank you for the tip!!! I was able to point to the sources folder separately using the "manage libraries" option in NetBeans 5.5 .... I'll post what i find.

Thank you for your quick replies!!!

fv
federico_vela_pfederico_vela_p
I am, in fact, now able to see the axis source code. Thank you! that solves part of my problem.

However I cannot log in anymore...

Caused by: INVALID_LOGIN: Invalid username or password or locked out.

i know the un/pw is good ... so how do you get locked out???!!!????
federico_vela_pfederico_vela_p
OK I got rid of the logon error... i guess test database is only enabled for version 7 and i'm using version six .. so nevermind that problem ... i'm going to try the breakpoints. thanks

SuperfellSuperfell
test.salesforce.com supports the all same versions of the API as the production system.
federico_vela_pfederico_vela_p
SimonF,

Thank you soooo much for your help, it helped me narrow down the problem. And i realized,,, (you'd think i could do this by now) ... i was getting the Iterator from the wrong array!!!! 8-|

look at the code above.... i'm doing mElem.iterator() and it should be the other list.

Thank you very much!!!!!!!

sorry for the stupidity.

fv
SuperfellSuperfell
You could probably just do .toArray() and leave all the iterator stuff out.
federico_vela_pfederico_vela_p
well, that was the original code, but i was getting a class cast exception ... but it was probably trying to cast the null pointers that were the original problem.

Thank you, i will try that, as it is a much cleaner way ...

fv