[concurrency-interest] JLS: finality of "enclosing instance" of inner classes

Neal Gafter neal at gafter.com
Mon Mar 15 11:04:26 EDT 2010


Matthias-

The spec also omits mention of the finality of cached copies of captured
local variables. I believe these omissions in the spec are bugs.

Cheers,
Neal

On Mon, Mar 15, 2010 at 4:37 AM, Matthias Ernst <matthias at mernst.org> wrote:

> Hi,
>
> does the JLS contain any language about the finality of the enclosing
> instance reference? In practice, javac maps the "outer this" to a final
> field "this$0", assigned in the inner class' constructor which would render
> it safely published as of JLS 17.5 ("Final field semantics"). However, I
> couldn't find any language in the spec regarding this.
>
> I stumbled over this looking at how java.util.HashMap constructs its
> collection views lazily:
>
>   960       private Set<Map.Entry<K,V>> entrySet0() {
>   961           Set<Map.Entry<K,V>> es = entrySet;
>   962           return es != null ? es : (entrySet = new EntrySet());
>
>
>   963       }
>
> (http://www.docjar.com/html/api/java/util/HashMap.java.html)
>
> This is only safe if final field semantics apply to enclosing instances.
>
> Thanks
> Matthias
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20100315/42d3c13d/attachment-0001.html>


More information about the Concurrency-interest mailing list