Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1212653

java.io.DataOutputStream align() spins in infinite loop

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0beta
    • CPU:
      sparc
    • OS:
      solaris_2.4
    • Verification:
      Not verified

      Description

      [jdn June 29, 1995]
      From looking at the source code for align() I don't understand how it
      can work. For the case where the number of bytes to align to is 0 it throws a
      "divide by zero" exception which seems a bit extreme -- perhaps it should just
      return without doing anything. For the case where the number of bytes is != 0
      it appears like it will spin in a loop writing zeros to the output stream -- I don't see
      how it can ever break out of the loop since 'n' is never changed and 'written' is
      an instance variable that won't be updated either by writing to the next output stream
      in the chain. Note that I haven't actually seen this behavior at runtime. I'm just
      eyeballing the code.

          /**
           * Aligns. This is useful when data fields have
           * to be aligned on a n byte boundary.
           * @param n the number of bytes to align on
           */
          public final void align(int n) {
              OutputStream out = this.out;
              while ((written % n) != 0) {
                  out.write(0);
              }
          }

        Attachments

          Activity

            People

            • Assignee:
              ahoffsunw Arthur Hoff (Inactive)
              Reporter:
              jdn Jeffrey Nisewanger (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: