We're updating the issue view to help you get more done. 

ICU4J MeasureUnit initialization race & deadlock

Description

There is a static initialization race and deadlock that can occur between classes MeasureUnit and Currency.

The problem is that the static block for MeasureUnit instantiates instances of class Currency, and that Currency is a subclass of MeasureUnit. This scenario is a known Java thread safety problem if concurrent threads separately start to initialize the two classes.

This code reliably deadlocks for me, running against ICU 56:

1 2 3 4 5 6 7 8 9 10 11 12 public static void main(String[] args) { System.out.println("Hello, World."); Thread thread = new Thread() { @Override public void run() { Set<String> measureUnitTypes = MeasureUnit.getAvailableTypes(); } }; thread.start(); Currency cur = Currency.getInstance(ULocale.ENGLISH); try {thread.join();} catch(InterruptedException e) {}; System.out.println("Done w thread");

A possible fix is attached. Still checking it out.

Environment

Status

Assignee

Andy Heninger

Reporter

Andy Heninger

Labels

Time Needed

Hours

tracCreated

Dec 11, 2015, 12:40 AM

tracOwner

andy

tracProject

ICU4J

tracReporter

andy

tracResolution

fixed

tracReviewer

markus

tracStatus

closed

tracWeeks

0.2

Components

Fix versions

Priority

critical