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

Floating Point Error (divide by zero) in BasicScrollBarUI

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 1.2.0
    • 1.2.0
    • client-libs
    • swing1.0.2
    • x86
    • windows_nt



      Name: joT67522 Date: 01/08/98


      I am currently developing a java application (for
      NT) that uses both Swing and JDBC to access a MS
      Access db. A Bug in the Access driver causes a
      SQL Exception to occur on any SQL query involving
      a number after a floating point error has occured
      (like a divide by zero).  I have found that the
      default behavior of the BasicScrollBarUI (simply
      using a JScrollPane) has two divide by zero
      errors.

      Refering to the 0.7 src release, they occur on
      lines 457 and 541.  I have the current code and
      my fix to those lines below.  The fix assumes
      that a number divided by zero is infinity, and
      zero times infinity is zero. It returns the same
      result as if the calculation occured, but with
      out causing a fp error.

      current:
      457        int thumbH = (int)(trackH * (extent / range));

      fix:
              int thumbH = (trackH == 0) ? 0 : (range == 0) ? Integer.MAX_VALUE :
                 (int)(trackH * (extent / range));

      current:
      541        int thumbW = (int)(trackW * (extent / range));

      fix:
              int thumbW = (trackW == 0) ? 0 : (range == 0) ? Integer.MAX_VALUE :
                  (int)(trackW * (extent / range));
      (Review ID: 22709)
      ======================================================================

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: