2

I'm seeing a strange issue involving a JLabel that is used to display a range of numbers. The text of the label is typically something like 0.0 - 100.0 (for example). The problem is that for a select few users, the text appears garbled. In this example, the text would show up as /-/,0//-/.

Here's what I know so far:

  • It appears to be some sort of off-by-one bug since each character displayed is one Unicode character behind the expected character.
  • The dash character between the two numbers is hard-coded in the application as a string literal.
  • It's happening on various versions of Oracle JVMs including 1.6.x and 1.7.x.
  • It's happening on a few select Windows 7 machines.

What could cause this type of problem? What else should I investigate? Thanks.

Jacob Wallace
  • 887
  • 2
  • 12
  • 24
  • Unfortunately I cannot reproduce the issue myself. The code is pretty simple. It's basically just setting the text of the label using two numbers that have been formatted using a NumberFormat and a dash that's a string literal. – Jacob Wallace Apr 19 '13 at 23:57
  • 1
    So you don't have access to the code? It's pretty difficult to diagnose without it. – devrobf Apr 20 '13 at 00:00
  • 3
    We have a similar problem with our java editor josm (see https://josm.openstreetmap.de/ticket/8488). I have two questions for you: Does your JLabel use a custom font, and what locales have the users. – Dirk Stöcker Apr 20 '13 at 11:10
  • 1
    @DirkStöcker, your issue appears to be the exact same thing. My label does have a font explicitly set (Arial plain 12pt.). I can confirm locales on Monday, but they're likely en_US and en_CA. I'm leaning towards it being a font issue because we don't see the issue with most other labels in the app. – Jacob Wallace Apr 20 '13 at 21:43
  • 1
    Two more things that could explain this bug: * Users may have installed **gdipp** (alternative Windows font renderer) that suffers [a similar bug](https://code.google.com/p/gdipp/issues/detail?id=155). * Corruptions in the **Windows font cache** (%WINDIR%\System32\FNTCACHE.DAT) sometimes cause similar behaviour. Users should try to delete this file and reboot their PC. – vip Apr 21 '13 at 15:40
  • @vip, I'm going to have one of the users clear the font cache on Monday. I'll update later with the results. – Jacob Wallace Apr 21 '13 at 18:52
  • 1
    @vip, clearing the font cache fixed the issue! Please add an answer so I can accept it. – Jacob Wallace Apr 22 '13 at 15:55

2 Answers2

4

This happens when you're setting the font of your JLabel to a font corrupted in the Windows font cache.

To rebuild the cache: as administrator, delete this file and reboot the PC:

del %WINDIR%\System32\FNTCACHE.DAT
vip
  • 1,707
  • 2
  • 16
  • 46
0

It looks like an errant DateFormat, instances of which are "are generally not synchronized." If it's intermittent, rather than selective, verify correct use of invokeLater(), and "create separate format instances for each thread." See also Format.

Addendum: The errant symbols might arise from the DateFormatSymbols or DecimalFormatSymbols used by concrete subclasses of Format. You can verify correct use of the event dispatch thread in several ways:

  • Examine the result of SwingUtilities.isEventDispatchThread().

  • Employ one of the schemes shown in the articles cited here.

  • Inspect the source code following the principles summarized in Memory Consistency Properties.

As you cannot reproduce the problem, you will have to enlist the help of your users. Ideally, you will want to solicit the following:

  • Host name, platform, locale & JVM version from System.getProperty()?

  • Intermittent or consistent?

  • Screenshots?

You can make it easier for the user by filling in some details in a message prepared using Desktop#mail(), as suggested here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I'm not following your answer. Can you elaborate more? There is no DateFormat involved, just a NumberFormat. Also, why would the string literal dash be off-by-one in the label if this had anything to do with the format object? I think it's likely something related to a strange system configuration or locale thing, no? – Jacob Wallace Apr 20 '13 at 02:32