Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8273790: Potential cyclic dependencies between Gregorian and CalendarSystem #5683

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -111,7 +111,9 @@ private static void initNames() {
}
}

private static volatile Gregorian GREGORIAN_INSTANCE;
private static final class GregorianHolder {
private static final Gregorian GREGORIAN_INSTANCE = new Gregorian();
}

/**
* Returns the singleton instance of the <code>Gregorian</code>
@@ -120,17 +122,7 @@ private static void initNames() {
* @return the <code>Gregorian</code> instance
*/
public static Gregorian getGregorianCalendar() {
var gCal = GREGORIAN_INSTANCE;
if (gCal != null) {
return gCal;
}
synchronized (CalendarSystem.class) {
gCal = GREGORIAN_INSTANCE;
if (gCal == null) {
gCal = GREGORIAN_INSTANCE = new Gregorian();
}
}
return gCal;
return GregorianHolder.GREGORIAN_INSTANCE;
}

/**
@@ -145,7 +137,7 @@ public static Gregorian getGregorianCalendar() {
*/
public static CalendarSystem forName(String calendarName) {
if ("gregorian".equals(calendarName)) {
return getGregorianCalendar();
return GregorianHolder.GREGORIAN_INSTANCE;
}

if (!initialized) {
@@ -72,6 +72,12 @@ private static void testConcurrentClassLoad() throws Exception {
// add a couple of tasks which directly invoke sun.util.calendar.CalendarSystem#getGregorianCalendar()
tasks.add(new GetGregorianCalTask(taskTriggerLatch));
tasks.add(new GetGregorianCalTask(taskTriggerLatch));
// before triggering the tests make sure we have created the correct number of tasks
// the countdown latch uses/expects
if (numTasks != tasks.size()) {
throw new RuntimeException("Test setup failure - unexpected number of tasks " + tasks.size()
+ ", expected " + numTasks);
}
final ExecutorService executor = Executors.newFixedThreadPool(tasks.size());

This comment has been minimized.

@naotoj

naotoj Sep 24, 2021
Member

Asserting tasks.size() == numTasks may help here.

This comment has been minimized.

@jaikiran

jaikiran Sep 25, 2021
Author Member

Yes, that makes sense. I've updated the test to add this check.

try {
final Future<?>[] results = new Future[tasks.size()];
@@ -168,4 +174,4 @@ public Object call() {
}
}
}
}
}