-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b78
-
generic
-
generic
A DESCRIPTION OF THE REGRESSION :
The ThreadLocal documentation implies that set() is not needed for ThreadLocal-s which override initialValue(), suggesting that a ThreadLocal subclass can prevent malicious modification by overriding set() to throw an exception. This works in 1.4 and 5.0, but not in Mustang, because set() is now used to install the value returned from initialValue(). Based on the javadoc and the old behavior, our application overrides set() to throw UnsupportedOperationException for ThreadLocal-s whose return value should always be the same reference. This code does not run without modification on Mustang.
See the test case for a stripped down version of an ImmutableThreadLocal abstract class which no longer works.
REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
On 1.4 and 1.5 this program prints a single line, on Mustang it calls set(), resulting in a thrown UnsupportedOperationException.
public class aa
{
/**
* {@link ThreadLocal} guaranteed to always return the same reference.
*/
abstract public static class ImmutableThreadLocal extends ThreadLocal
{
public void set(final Object value)
{
throw new UnsupportedOperationException("ImmutableThreadLocal value should not be changed");
}
// force override
abstract protected Object initialValue();
}
private static final ThreadLocal cache = new ImmutableThreadLocal() {
public Object initialValue()
{
return Thread.currentThread().getName();
}
};
public static void main(final String[] args)
{
System.out.println("cache.get() = " + cache.get());
}
}
RELEASE LAST WORKED:
5.0 Update 6
RELEASE TEST FAILS:
mustang-beta
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
We were expecting that our existing code would be called in the same way as before.
ACTUAL -
Our code throws UnsupportedOperationException from an overriden version of ThreadLocal.set(), and that exception was thrown.
OBSERVED APPLICATION IMPACT:
Applications that use this technique in an attempt to prevent inconsistent internal state will instead fail to work without modification.
Release Regression From : mustang
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
The ThreadLocal documentation implies that set() is not needed for ThreadLocal-s which override initialValue(), suggesting that a ThreadLocal subclass can prevent malicious modification by overriding set() to throw an exception. This works in 1.4 and 5.0, but not in Mustang, because set() is now used to install the value returned from initialValue(). Based on the javadoc and the old behavior, our application overrides set() to throw UnsupportedOperationException for ThreadLocal-s whose return value should always be the same reference. This code does not run without modification on Mustang.
See the test case for a stripped down version of an ImmutableThreadLocal abstract class which no longer works.
REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
On 1.4 and 1.5 this program prints a single line, on Mustang it calls set(), resulting in a thrown UnsupportedOperationException.
public class aa
{
/**
* {@link ThreadLocal} guaranteed to always return the same reference.
*/
abstract public static class ImmutableThreadLocal extends ThreadLocal
{
public void set(final Object value)
{
throw new UnsupportedOperationException("ImmutableThreadLocal value should not be changed");
}
// force override
abstract protected Object initialValue();
}
private static final ThreadLocal cache = new ImmutableThreadLocal() {
public Object initialValue()
{
return Thread.currentThread().getName();
}
};
public static void main(final String[] args)
{
System.out.println("cache.get() = " + cache.get());
}
}
RELEASE LAST WORKED:
5.0 Update 6
RELEASE TEST FAILS:
mustang-beta
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
We were expecting that our existing code would be called in the same way as before.
ACTUAL -
Our code throws UnsupportedOperationException from an overriden version of ThreadLocal.set(), and that exception was thrown.
OBSERVED APPLICATION IMPACT:
Applications that use this technique in an attempt to prevent inconsistent internal state will instead fail to work without modification.
Release Regression From : mustang
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.