[concurrency-interest] Question about final field semantic in case of a race

Aleksey Shipilev shade at redhat.com
Thu Aug 31 05:40:29 EDT 2017

On 08/31/2017 11:17 AM, Thomas Krieger wrote:
> I am running the following JCStressTest on a Raspberry Pi 3 with a Java(TM) SE Runtime Environment
> (build 1.8.0_65-b17) Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode):
> @JCStressTest
> @Outcome(id = "0", expect = Expect.ACCEPTABLE, desc = "Default outcome.")
> @State
> public class BigDecimalToString {
>     private final  BigDecimal testBigDecimal = new BigDecimal("0.56");
>     @Actor
>     public void actor1(IntResult1 r) {
>         testBigDecimal.toString().length();
>     }
>     @Actor
>     public void actor2(IntResult1 r) {
>         testBigDecimal.toString().length();
>     }    
> }
> In about half of the iterations, I see the following Exception:> java.lang.NullPointerException


> Or, because of the final field, all threads should have only seen an
> initialized value?

String is published by race, but String.value is final, so it should be safe. Seeing NPE on
dereferencing String.value is weird, and probably points to a compiler bug. Run with more modern
JDK?. It is also not clear if you run ARMv7 or AArch64 VM (not all RPi 3 distros are 64-bit, and
many identify RPi 3 as 32-bit ARM).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20170831/07d0aced/attachment.sig>

More information about the Concurrency-interest mailing list