JDK-6459089 : ArithmeticException with JEditorPane containing HTML
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-08-10
  • Updated: 2011-01-19
  • Resolved: 2006-08-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
6 b97Fixed
Related Reports
Relates :  
Compile and run the following test case. When it loads, hit PageUp or PageDown:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class EPTest extends JFrame {
    public EPTest() {
        JEditorPane ep = new JEditorPane();
        getContentPane().add(new JScrollPane(ep));

    private static void createAndShowGUI(String[] args) {
        EPTest test = new EPTest();
        test.setSize(400, 400);
    public static void main(final String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {

The following exception is printed:

Exception in thread "AWT-EventQueue-0" java.lang.ArithmeticException: / by zero
	at javax.swing.text.DefaultEditorKit$VerticalPageAction.actionPerformed(DefaultEditorKit.java:1414)
	at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1634)
	at javax.swing.JComponent.processKeyBinding(JComponent.java:2824)
	at javax.swing.JComponent.processKeyBindings(JComponent.java:2859)
	at javax.swing.JComponent.processKeyEvent(JComponent.java:2787)
	at java.awt.Component.processEvent(Component.java:5812)
	at java.awt.Container.processEvent(Container.java:2045)
	at java.awt.Component.dispatchEventImpl(Component.java:4407)
	at java.awt.Container.dispatchEventImpl(Container.java:2103)
	at java.awt.Component.dispatchEvent(Component.java:4237)
	at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:693)
	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:952)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:824)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:657)
	at java.awt.Component.dispatchEventImpl(Component.java:4279)
	at java.awt.Container.dispatchEventImpl(Container.java:2103)
	at java.awt.Window.dispatchEventImpl(Window.java:2429)
	at java.awt.Component.dispatchEvent(Component.java:4237)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Can also be reproduced with SwingSet2:

  Start SwingSet2, select an Internal Frame (just click at "Frame 0")
  then switch to the "Source Code" tab, and when the source is
  loaded, hit PageDown.

This is a regression introduced by the fix to 6244705.

Previously, the code looked like:
yOffset = direction * (int)Math.ceil(scrollAmount / (double)h) * h; 

Now there is:
scrollAmount = direction * scrollAmount / h * h;

The problem appears to be the fact that "h" is 0 when the caret position is within the header of the document. The new code, when dividing by 0, throws an exception. Previously, however, we were using doubles. The result of dividing by 0 was "Infinity", which was then casted to the int value 2147483647.

It looks to me like both old and new code are wrong in their dealing with 0, but the previous code (at least) didn't throw an exception.

SUGGESTED FIX http://javaweb.sfbay/jcg/1.6.0-mustang/swing/6459089/

EVALUATION We try to adjust scrollAmount so that it is a multiple of caret height. If caret height is zero, let's just skip the adjustment part.