JDK-5082289 : NPE @ sun.awt.font.AdvanceCache.get(AdvanceCache.java:135)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_10
  • CPU: generic,sparc
  • Submitted: 2004-08-03
  • Updated: 2006-05-19
  • Resolved: 2004-09-20
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 Availabitlity Release.

To download the current JDK release, click here.
1.4.2_07 b01Fixed
We have seen our NETSMART client run into paint issues (one 
particular component becoming unusable - requiring a restart of the 
client) due to a NullPointerException thrown from java internals. 
This problem has recently been seen by our test team atleast twice and 
they have raised fix priority on this.

        at sun.awt.font.AdvanceCache.get(AdvanceCache.java:135)
        at java.awt.font.TextLayout$OptInfo.getAdvance(TextLayout.java:248)
        at java.awt.font.TextLayout$OptInfo.getLogicalBounds(TextLayout.java:261)
        at sun.awt.font.Decoration$DecorationImpl.drawTextAndEmbellishments(Decoration.java:243)
        at sun.awt.font.Decoration$DecorationImpl.drawTextAndDecorations(Decoration.java:273)
        at java.awt.font.TextLayout$OptInfo.draw(TextLayout.java:298)
        at java.awt.font.TextLayout.draw(TextLayout.java:2660)
        at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2595)
In a related problem on 1.4.2 when the cache is flushed, the variable 'i' is not reset
but can still be used as described in incident 709901

java.lang.ArrayIndexOutOfBoundsException: 1321
        at sun.awt.font.AdvanceCache.get(AdvanceCache.java:168)
        at java.awt.font.TextLayout
$OptInfo.handleGetVisualBounds(Unknown Source)
        at sun.awt.font.Decoration.getVisualBounds(Decoration.java:105)
        at java.awt.font.TextLayout$OptInfo.getVisualBounds(Unknown
        at java.awt.font.TextLayout.getBounds(Unknown Source)

the submitter pointed out that 
cacheNum = 0;
should become
i = cacheNum = 0;

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.4.2_07 FIXED IN: 1.4.2_07 INTEGRATED IN: 1.4.2_07

WORK AROUND Possibly (customer is yet to confirm this workaround) by using this flag: "-Dsun.awt.font.advancecache=off"

EVALUATION The AdvanceCache.get() method is not thread-safe which could be the cause of this problem althouyh absent a test case its hard to say for sure, or even to test a fix. The observed code problem is that it synchronises entry to a block on a variable "cache", but inside that block assigns a new object to "cache" so 2 threads can enter, one on each variable and be accessing state variables which are not meant for simultaneous access This isn't a problem in 1.5 as the cache is disabled and we probably could just delete the class .. If a 1.4.X fix is needed probably the easiest thing is to chose a new object on which to synchronise. ###@###.### 2004-08-03 ============================