Skip to content

Commit 8f8ff52

Browse files
committedJul 13, 2020
8248486: SafeThread illegal access to java.lang private fields should be removed
Reviewed-by: chegar, rriggs, mchung, alanb
1 parent 83a458c commit 8f8ff52

File tree

2 files changed

+13
-38
lines changed

2 files changed

+13
-38
lines changed
 

‎src/java.base/share/classes/module-info.java

-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@
193193
java.net.http,
194194
java.rmi,
195195
java.security.jgss,
196-
java.xml,
197196
jdk.attach,
198197
jdk.charsets,
199198
jdk.compiler,
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,34 +24,30 @@
2424
*/
2525
package com.sun.org.apache.xml.internal.utils;
2626

27+
import java.util.concurrent.atomic.AtomicInteger;
28+
2729
/**
28-
* This is a combination of ThreadControllerWrapper's inner class SafeThread
29-
* that was introduced as a fix for CR 6607339
30-
* and sun.misc.ManagedLocalsThread, a thread that has it's thread locals, and
31-
* inheritable thread locals erased on construction. Except the run method,
32-
* it is identical to sun.misc.ManagedLocalsThread.
30+
* Represents a safe thread that does not inherit thread-locals and runs only
31+
* once.
3332
*/
3433
public class SafeThread extends Thread {
35-
36-
private static final jdk.internal.misc.Unsafe UNSAFE;
37-
private static final long THREAD_LOCALS;
38-
private static final long INHERITABLE_THREAD_LOCALS;
39-
4034
private volatile boolean ran = false;
4135

36+
private static final AtomicInteger threadNumber = new AtomicInteger(1);
37+
private static String threadName() {
38+
return "SafeThread-" + threadNumber.getAndIncrement();
39+
}
40+
4241
public SafeThread(Runnable target) {
43-
super(target);
44-
eraseThreadLocals();
42+
this(null, target, threadName());
4543
}
4644

4745
public SafeThread(Runnable target, String name) {
48-
super(target, name);
49-
eraseThreadLocals();
46+
this(null, target, name);
5047
}
5148

5249
public SafeThread(ThreadGroup group, Runnable target, String name) {
53-
super(group, target, name);
54-
eraseThreadLocals();
50+
super(group, target, name, 0, false);
5551
}
5652

5753
public final void run() {
@@ -69,24 +65,4 @@ public final void run() {
6965
}
7066
super.run();
7167
}
72-
73-
/**
74-
* Drops all thread locals (and inherited thread locals).
75-
*/
76-
public final void eraseThreadLocals() {
77-
UNSAFE.putReference(this, THREAD_LOCALS, null);
78-
UNSAFE.putReference(this, INHERITABLE_THREAD_LOCALS, null);
79-
}
80-
81-
static {
82-
UNSAFE = jdk.internal.misc.Unsafe.getUnsafe();
83-
Class<?> t = Thread.class;
84-
try {
85-
THREAD_LOCALS = UNSAFE.objectFieldOffset(t.getDeclaredField("threadLocals"));
86-
INHERITABLE_THREAD_LOCALS = UNSAFE.objectFieldOffset(t.getDeclaredField("inheritableThreadLocals"));
87-
} catch (Exception e) {
88-
throw new Error(e);
89-
}
90-
}
91-
9268
}

0 commit comments

Comments
 (0)
Please sign in to comment.