Uploaded image for project: 'Axis2'
  1. Axis2
  2. AXIS2-5751

Databinding- BeanUtil.getPullParser() throws NullPointerException

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.7.1
    • 1.7.2
    • adb
    • None
    • Important

    Description

      Test Case 1 (stacktrace.txt):

      My service operation returns an Response Object, having a header and content. In Header i have in CustomError (see code below) object that describes application errors and in content i have the payload.

      In my specific case i'm calling the service operation which returns an Response object having in header a custom error without details. This causes the operation to fail because the pull parser wants to instantiate the result of the getter method witch is a null java.lang.Object.

      Test code:

          public class CustomError {
                private Error code;
                private Object detail;
      
               // constructors
               // getters and setters
          }
           ..
      
          new CustomError(code41);   // detail is null
      

      in adb:

      BeanUtil.java
      Object value;
       if (readMethod != null) {
           readMethod.setAccessible(true);
           value = readMethod.invoke(beanObject); // value is null
       } else {
           throw new AxisFault("Property '" + propertyName + "' in bean class '"
                                              + beanClass.getName() + "'is not readable.");
       }
      ......
      ......
       }else {
           addTypeQname(elemntNameSpace, propertyQnameValueList, property,
                                       beanName, processingDocLitBare);
           if (Object.class.equals(ptype)) {
               //this is required to match this element prefix as
               //root element's prefix.
               QName qNamefortheType = (QName) typeTable
                                      .getComplexSchemaMap().get(
                                              getClassName(beanClass));
               OMFactory fac = OMAbstractFactory.getOMFactory();
               QName elementName;
               OMElement element;
               if (elemntNameSpace != null) {
                   elementName = new QName(
                                          elemntNameSpace.getNamespaceURI(),
                                          property.getName(),
                                          qNamefortheType.getPrefix());
               } else {
                   elementName = new QName(property.getName());
               }
                              
               if(SimpleTypeMapper.isSimpleType(value)){
                    element = fac.createOMElement(elementName);
                    element.addChild(fac.createOMText(SimpleTypeMapper
                                          .getStringValue(value)));
               }else{
                     // value is null !!!
                     XMLStreamReader xr = BeanUtil.getPullParser(value,
                                           elementName, typeTable, qualified, false);
      
      BeanUtil.java
       public static XMLStreamReader getPullParser(Object beanObject,
                                                      QName beanName,
                                                      TypeTable typeTable,
                                                      boolean qualified,
                                                      boolean processingDocLitBare) {
      
              Class beanClass = beanObject.getClass(); // NullPointerException
               ..............
      

      Testcase 2 (stacktrace_array_tc2.txt)

      return of the operation is also a complex structure but now inside the returned object at a deeper level there is a Array List of String arrays. Here another problem because the BeanUtil tries to get the package of the class [Ljava.lang.Object; meaning the arrays of object which is NULL resulting to NullPointerException!

      BeanUtil.java
      if (typeTable != null && qualified) {
                      QName qNamefortheType = typeTable.getQNamefortheType(beanClass.getName());
                      if (qNamefortheType == null) {
                          // beanClass.getPackage() is null for class [Ljava.lang.Object; (Object[].class)
                          qNamefortheType = typeTable.getQNamefortheType(beanClass.getPackage().getName());
                      }
                      if (qNamefortheType == null) {
                          throw new AxisFault("Mapping qname not fond for the package: " +
                                              beanObject.getClass().getPackage().getName());
                      }
      

      Attachments

        1. AXIS2-5751-ServiceTest.7z
          1 kB
          Vasile Bucur
        2. stacktrace_array_tc2.txt
          6 kB
          Vasile Bucur
        3. stacktrace.txt
          5 kB
          Vasile Bucur

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            vbucur Vasile Bucur
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment