United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-5082289 NPE @ sun.awt.font.AdvanceCache.get(AdvanceCache.java:135)
JDK-5082289 : NPE @ sun.awt.font.AdvanceCache.get(AdvanceCache.java:135)

Details
Type:
Bug
Submit Date:
2004-08-03
Status:
Resolved
Updated Date:
2006-05-19
Project Name:
JDK
Resolved Date:
2004-09-20
Component:
client-libs
OS:
generic,solaris_10
Sub-Component:
2d
CPU:
sparc,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.2
Fixed Versions:
1.4.2_07 (b01)

Related Reports

Sub Tasks

Description
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.

java.lang.NullPointerException
        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
Source)
        at java.awt.font.TextLayout.getBounds(Unknown Source)
        ...

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

                                    

Comments
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
============================
                                     
2004-08-03
WORK AROUND

Possibly (customer is yet to confirm this workaround) by using this flag:

"-Dsun.awt.font.advancecache=off"
                                     
2004-10-02
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


                                     
2004-10-02



Hardware and Software, Engineered to Work Together