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

(ch) FileLock: negative param and overflow issues

XMLWordPrintable

    • b11
    • sparc
    • solaris_9

      The Right Thing is to apply the same checks to overlaps() as to the
      constructor.

      static void checkValidRange(long position, long size) {
      if (position < 0)
      throw new IllegalArgumentException("Negative position");
      if (size < 0)
      throw new IllegalArgumentException("Negative size");
      if (position + size < 0)
      throw new IllegalArgumentException("Negative position + size");
      }

      We could call the above in both the constructor and overlaps().
      What happens if the caller passes negative values to overlaps()?

      But this is slightly incompatible. No doubt some application is
      relying on being able to pass negative args to overlaps(). Anyways, a
      CCC is called for to settle this issue.

          public final boolean overlaps(long position, long size) {
              checkValidRange(position, size);
              return ((position + size > this.position) &&
                      (this.position + this.size > position));
          }

      ###@###.###

            bpb Brian Burkhalter
            mmcclosksunw Michael Mccloskey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: