Uploaded image for project: 'OpenDJ'
  1. OpenDJ
  2. OPENDJ-2299

ResultCode.valueOf throw java.lang.IndexOutOfBoundsException if the value is not in [0,16655[

    Details

      Description

      The safe check is not correct

      Currently:

       if (intValue >= 0 || intValue < ELEMENTS.length) {
      

      should be:

       if (intValue >= 0 && intValue < ELEMENTS.length) {
      

      I like (0 <= intValue && intValue < ELEMENTS.length), I found it more readable

      ResultCode.java
          /**
           * Returns the result code having the specified integer value as defined in
           * RFC 4511 section 4.1.9. If there is no result code associated with the
           * specified integer value then a temporary result code is automatically
           * created in order to handle cases where unexpected result codes are
           * returned from the server.
           *
           * @param intValue
           *            The integer value of the result code.
           * @return The result code.
           */
          public static ResultCode valueOf(final int intValue) {
              ResultCode resultCode = null;
      
              if (intValue >= 0 || intValue < ELEMENTS.length) {
                  resultCode = ELEMENTS[intValue];
              }
      
              if (resultCode == null) {
                  resultCode =
                          new ResultCode(intValue, LocalizableMessage.raw("undefined(" + intValue + ")"),
                                  true);
              }
      
              return resultCode;
          }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                matthew Matthew Swift
                Reporter:
                quentin.castel Quentin CASTEL [X] (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: