Uploaded image for project: 'EJBCA'
  1. EJBCA
  2. ECA-9448

Regression: Changes in EndEntityProfileSessionBean and CertificateProfileSessionBean in try-with-resources produce incomplete xml

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: EJBCA 7.4.3
    • Fix Version/s: EJBCA 7.4.3
    • Component/s: None
    • Labels:
    • Issue discovered during:
      Jenkins

      Description

      The recent change in EndEntityProfileSessionBean and CertificateProfileSessionBean in try-with-resources produce incomplete xml ECA-9343. Discovered with org.ejbca.core.protocol.ws.EjbcaWSTest.

      The problem is related to handling of XMLEncoder as a resource. The actual close method is:

          /**
           * This method calls <code>flush</code>, writes the closing
           * postamble and then closes the output stream associated
           * with this stream.
           */
          public void close() {
              flush();
              writeln("</java>");
              try {
                  out.close();
              }
              catch (IOException e) {
                  getExceptionListener().exceptionThrown(e);
              }
          }
      

      if we do like this:

              try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(baos)) {
                  encoder.writeObject(profile.saveData());
                  encoder.flush(); // try-with-resource closes it
                  return baos.toByteArray();
              } catch (IOException e) {
                  String msg = "Could not encode profile with ID " + profileId + " to XML: " + e.getMessage();
                  LOG.debug(msg, e);
                  throw new IllegalStateException(msg, e);
              }
      

      we return result without </java> end tag.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              andrey_helmes Andrey Sergeev
              Reporter:
              andrey_helmes Andrey Sergeev
              Verified by:
              Tomas Gustavsson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Time Tracking

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