JLS 17.5 Examples

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

JLS 17.5 Examples

JSR166 Concurrency mailing list
Hi,

about the two examples in JLS 17.5 https://docs.oracle.com/javase/specs/jls/se11/html/jls-17.html#jls-17.5

- In Example 17.5-1, wouldn't it be more accurate to replace "guaranteed to see 3" with "cannot see 0"? Because it could still throw a NullPointerException. As access to f is (deliberately) not synchronized, the second dereference of f could return null. In fact, one could get rid of the non-null check altogether.
- Example 17.5-2 seems to refer to previous implementations of String which still had an offset field.

Is that accurate?

Greets,
Felix



--
andrena objects ag
Albert-Nestler-Str. 9
76131 Karlsruhe

t: <a href="tel:+49 (0) 721 6105 122" original_font_attr="-1" original_line_height_attr="">+49 (0) 721 6105 122
f: <a href="tel:+49 (0) 721 6105 140" original_font_attr="-1" original_line_height_attr="">+49 (0) 721 6105 140

http://www.andrena.de

Vorstand: Hagen Buchwald, Dr. Dieter Kuhn, Stefan Schürle
Aufsichtsratsvorsitzender: Rolf Hetzelberger

Sitz der Gesellschaft: Karlsruhe
Amtsgericht Mannheim, HRB 109694
USt-IdNr. DE174314824

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: JLS 17.5 Examples

JSR166 Concurrency mailing list

On Fri, Sep 28, 2018 at 6:03 AM Felix Riemann via Concurrency-interest <[hidden email]> wrote:
>
> Hi,
>
> about the two examples in JLS 17.5 https://docs.oracle.com/javase/specs/jls/se11/html/jls-17.html#jls-17.5
>
> - In Example 17.5-1, wouldn't it be more accurate to replace "guaranteed to see 3" with "cannot see 0"? Because it could still throw a NullPointerException. As access to f is (deliberately) not synchronized, the second dereference of f could return null. In fact, one could get rid of the non-null check altogether.

Agreed. It might be better to instead have the example just read f once.

Hans

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest