Hi Experts,

I have this method(generic-like) that saves entries from strusts action form and analyze for some purpose. However, I am having this error and I am checking null case in my code. any idea?


public void saveEntries(ActionForm aForm, boolean fromValBtn) {
        PropertyDescriptor pd[] = PropertyUtils.getPropertyDescriptors(aForm);
for(int i=0; i<pd.length; i++){
            Method reader = PropertyUtils.getReadMethod(pd[i]);

            if(reader != null && (reader.toString().length() > 0) ){
                Object obj = reader.invoke(aForm,new Object[] {});

getter from the form

public String getFmriId() {
        fmriId = functmriseq.getFunctmriseqId().toString();
        return fmriId;

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(
      at java.lang.reflect.Method.invoke(
      at org.kki.dcn.struts.utils.DcnDispatchUtilAction.saveEntries(

Caused by: java.lang.NullPointerException
      at org.kki.dcn.hibernate.mriSeq.Seqpar.getAmriId(
Who is Participating?
the NPE is happening in getAmriId at line 538
check that line for any references to vars that could be null, and add null checks there as required
dkim18Author Commented:
yeah..i can see that. since that saveEntries method handles many forms, is there any way that I can handle such a case from that method?
not from saveEntries(), you can't know what each method does internally.
Isn't it all your own code? If so, why not ensure that the save is not invoked without non-null parameters?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.