JDK-8015853 : java.lang.ArrayIndexOutOfBoundsException when running SwingSet2 demo
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2013-06-04
  • Updated: 2013-07-03
  • Resolved: 2013-06-06
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.
JDK 7 JDK 8
7u40Resolved 8 b96Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
Steps to reproduce:
1. Run SwingSet2 demo
2. Click on "Source" tab

Actual result: 
The following exception occurs.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 342
        at javax.swing.text.CompositeView.getView(CompositeView.java:160)
        at javax.swing.text.View.forwardUpdate(View.java:1151)
        at javax.swing.text.BoxView.forwardUpdate(BoxView.java:240)
        at javax.swing.text.View.changedUpdate(View.java:788)
        at javax.swing.text.html.BlockView.changedUpdate(BlockView.java:341)
        at javax.swing.text.View.forwardUpdateToView(View.java:1212)
        at javax.swing.text.View.forwardUpdate(View.java:1183)
        at javax.swing.text.BoxView.forwardUpdate(BoxView.java:240)
        at javax.swing.text.View.changedUpdate(View.java:788)
        at javax.swing.text.html.BlockView.changedUpdate(BlockView.java:341)
        at javax.swing.text.View.forwardUpdateToView(View.java:1212)
        at javax.swing.text.View.forwardUpdate(View.java:1183)
        at javax.swing.text.BoxView.forwardUpdate(BoxView.java:240)
        at javax.swing.text.View.changedUpdate(View.java:788)
        at javax.swing.text.html.BlockView.changedUpdate(BlockView.java:341)
        at javax.swing.plaf.basic.BasicTextUI$RootView.changedUpdate(BasicTextUI.java:1630)
        at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.changedUpdate(BasicTextUI.java:1891)
        at javax.swing.text.AbstractDocument.fireChangedUpdate(AbstractDocument.java:230)
        at javax.swing.text.html.HTMLDocument.fireChangedUpdate(HTMLDocument.java:1729)
        at javax.swing.text.html.HTMLDocument$HTMLReader.adjustEndElement(HTMLDocument.java:2470)
        at javax.swing.text.html.HTMLDocument$HTMLReader.flush(HTMLDocument.java:2525)
        at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:263)
        at javax.swing.JEditorPane.setText(JEditorPane.java:1415)
        at SwingSet2$5.run(SwingSet2.java:1042)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
        at java.awt.EventQueue.access$400(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:688)
        at java.awt.EventQueue$3.run(EventQueue.java:685)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:220)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:135)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:123)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:119)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:111)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)


Expected result: No exceptions should be thrown.
Comments
This problem was caused by the changes made under JDK-8014863. The calculation of index1 variable in the View.forwardUpdate() method is not correct. Suggested fix: Math.max((getViewCount() - 1), 0) should be used instead of getViewIndex(elem.getDocument().getLength(), Position.Bias.Forward).
04-06-2013