JDK-6245971 : Regression: IndexOutOfBoundsException when printing
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt:i18n
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris
  • CPU: x86
  • Submitted: 2005-03-25
  • Updated: 2010-07-29
  • Resolved: 2005-04-11
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 6
6 b32Fixed
Related Reports
Relates :  
Description
Following exception occur when trying to do printing.

----------System.err:(22/1413)----------
java.lang.IndexOutOfBoundsException
	at java.nio.CharBuffer.wrap(CharBuffer.java:352)
	at sun.print.PSPrinterJob.textOut(PSPrinterJob.java:1146)
	at sun.print.PSPathGraphics.drawString(PSPathGraphics.java:175)
	at sun.print.PSPathGraphics.drawString(PSPathGraphics.java:122)
	at sun.print.PSPathGraphics.drawString(PSPathGraphics.java:96)
	at PrintTest$_PrintTest$Printer.print(PrintTest.java:118)
	at sun.print.RasterPrinterJob.printPage(RasterPrinterJob.java:1916)
	at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1385)
	at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1216)
	at PrintTest$_PrintTest.actionPerformed(PrintTest.java:230)
	at java.awt.Button.processActionEvent(Button.java:388)
	at java.awt.Button.processEvent(Button.java:356)
	at java.awt.Component.dispatchEventImpl(Component.java:4036)
	at java.awt.Component.dispatchEvent(Component.java:3873)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:591)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:247)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:162)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:154)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:115)
STATUS:Failed.Applet thread threw exception: java.lang.IndexOutOfBoundsException
result: Failed. Execution failed: Applet thread threw exception: java.lang.IndexOutOfBoundsException

----------------------------------------

The testcase is at:
/java/j2se-sqe/i18n/workspaces/i18n_mustang_ws/i18n/bundles/b03/gs16-03.tar.gz

To reproduce:
1. expand above test suite.
2. goto i18n-mustang-int/i18n/src/GS
3. sh run_gs.sh -jdk:${JAVA_HOME}
other-functional/awt/print/PrintTest.java

The problem was observed on both Solaris and Linux platforms.
This was not happening at least in b24.


###@###.### 2005-03-25 09:09:56 GMT

Comments
SUGGESTED FIX PSPrinterJob.java line 1146: wrap the first parameter, cs.charsetChars (char[]), using CharBuffer. original: fontCS.encode(CharBuffer.wrap(cs.charsetChars, cs.offset, cs.offset + cs.length), bb, true); changeTo: fontCS.encode(CharBuffer.wrap(CharBuffer.wrap(cs.charsetChars), cs.offset, cs.offset + cs.length), bb, true); ###@###.### 2005-03-30 21:16:38 GMT Actually, instead of calling CharBuffer.wrap twice, change the last parameter from cs.offset+cs.length to cs.length will be better. ###@###.### 2005-04-05 21:00:53 GMT
30-03-2005

EVALUATION Printing is a 2D responsibility area. ###@###.### 2005-03-28 09:45:15 GMT The usage of NIO here was introduced in the recent fix for 4954012: Convert use of old sun.io APIs into new java.nio.charset APIs Assigning to the R/E for that bug for investigation as to the root cause. ###@###.### 2005-03-28 15:53:53 GM ###@###.### 2005-03-30 21:16:37 GMT The line 1146 originally had the following: fontCS.encode(CharBuffer.wrap(cs.charsetChars, cs.offset, cs.offset + cs.length), ... The IndexOutofBoundException was thrown because this is a call to static CharBuffer wrap(char[] array, int offset, int length) This worked fine when the offset is 0 because offset+length=length. This is the reason that a part of the test, which calls this API passes. However from the 2nd call, the offset is implemented, and offset+length > length. Then the OutofBoundaryException is thrown since the preconditions on the offset and length parameters do not hold Probably, it's originally programmed this way intending that this will make a call to static CharBuffer wrap(CharSequence csq, int start, int end) ###@###.### 2005-04-05 21:00:52 GMT
28-03-2005