Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1549

An incomplete fix for the NPE bugs in XSSimpleTypeDecl.java

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Invalid
    • None
    • None
    • None

    Description

      The fix revision 318723 was aimed to remove an NPE bug on the "fEnumeration" in the method "getLexicalEnumerations" of the file "/xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java" , but it is incomplete.
      Since the "fEnumeration" is an class field and also could be null during the run-time execution, it should also be null-checked before being dereferenced in other methods (e.g., Line 1311 in the method "checkFacets").

      The buggy code the proposed missing fixes should be made in is copied as bellowing:

      private void checkFacets(ValidatedInfo validatedInfo) throws InvalidDatatypeValueException {

      Object ob = validatedInfo.actualValue;
      String content = validatedInfo.normalizedValue;

      int length = fDVs[fValidationDV].getDataLength(ob);

      // maxLength
      if ( (fFacetsDefined & FACET_MAXLENGTH) != 0 ) {
      if ( length > fMaxLength ) {
      throw new InvalidDatatypeValueException("cvc-maxLength-valid",
      new Object[]

      {content, Integer.toString(length), Integer.toString(fMaxLength)}

      );
      }
      }

      //minLength
      if ( (fFacetsDefined & FACET_MINLENGTH) != 0 ) {
      if ( length < fMinLength ) {
      throw new InvalidDatatypeValueException("cvc-minLength-valid",
      new Object[]

      {content, Integer.toString(length), Integer.toString(fMinLength)}

      );
      }
      }

      //length
      if ( (fFacetsDefined & FACET_LENGTH) != 0 ) {
      if ( length != fLength ) {
      throw new InvalidDatatypeValueException("cvc-length-valid",
      new Object[]

      {content, Integer.toString(length), Integer.toString(fLength)}

      );
      }
      }

      //enumeration
      if ( ((fFacetsDefined & FACET_ENUMERATION) != 0 ) ) {
      boolean present = false;
      [Line 1311] for (int i = 0; i < fEnumeration.size(); i++) {
      [Line 1312] if (isEqual(ob, fEnumeration.elementAt))

      { present = true; break; }

      }
      if(!present){
      throw new InvalidDatatypeValueException("cvc-enumeration-valid",
      new Object []

      {content, fEnumeration.toString()}

      );
      }
      }

      //fractionDigits
      if ((fFacetsDefined & FACET_FRACTIONDIGITS) != 0) {
      int scale = fDVs[fValidationDV].getFractionDigits(ob);
      if (scale > fFractionDigits) {
      throw new InvalidDatatypeValueException("cvc-fractionDigits-valid",
      new Object[]

      {content, Integer.toString(scale), Integer.toString(fFractionDigits)}

      );
      }
      }

      //totalDigits
      if ((fFacetsDefined & FACET_TOTALDIGITS)!=0) {
      int totalDigits = fDVs[fValidationDV].getTotalDigits(ob);
      if (totalDigits > fTotalDigits) {
      throw new InvalidDatatypeValueException("cvc-totalDigits-valid",
      new Object[]

      {content, Integer.toString(totalDigits), Integer.toString(fTotalDigits)}

      );
      }
      }

      int compare;

      //maxinclusive
      if ( (fFacetsDefined & FACET_MAXINCLUSIVE) != 0 ) {
      compare = fDVs[fValidationDV].compare(ob, fMaxInclusive);
      if (compare != -1 && compare != 0) {
      throw new InvalidDatatypeValueException("cvc-maxInclusive-valid",
      new Object[]

      {content, fMaxInclusive}

      );
      }
      }

      //maxExclusive
      if ( (fFacetsDefined & FACET_MAXEXCLUSIVE) != 0 ) {
      compare = fDVs[fValidationDV].compare(ob, fMaxExclusive );
      if (compare != -1) {
      throw new InvalidDatatypeValueException("cvc-maxExclusive-valid",
      new Object[]

      {content, fMaxExclusive}

      );
      }
      }

      //minInclusive
      if ( (fFacetsDefined & FACET_MININCLUSIVE) != 0 ) {
      compare = fDVs[fValidationDV].compare(ob, fMinInclusive);
      if (compare != 1 && compare != 0) {
      throw new InvalidDatatypeValueException("cvc-minInclusive-valid",
      new Object[]

      {content, fMinInclusive}

      );
      }
      }

      //minExclusive
      if ( (fFacetsDefined & FACET_MINEXCLUSIVE) != 0 ) {
      compare = fDVs[fValidationDV].compare(ob, fMinExclusive);
      if (compare != 1) {
      throw new InvalidDatatypeValueException("cvc-minExclusive-valid",
      new Object[]

      {content, fMinExclusive}

      );
      }
      }

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            guangtai Guangtai Liang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 10m
                10m
                Remaining:
                Remaining Estimate - 10m
                10m
                Logged:
                Time Spent - Not Specified
                Not Specified