<p>Not sure if Bob's answer applies to your question, but if you're asking if a or b can be null when finalize() runs, the answer is yes - you'd need to do a null check. To guarantee that a and b dispose cleanly when relying on finalization, they're own finalize would have to do that instead of relying on reach ability via SomeService.</p>

<p>Sent from my phone</p>
<div class="gmail_quote">On May 13, 2012 4:30 PM, "Chris Vest" <<a href="mailto:mr.chrisvest@gmail.com">mr.chrisvest@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Hi,</div><div>I could not find any resources that I felt were clear and trustworthy enough, so...</div><div><br></div><div>I would like to have confirmed (or busted) my assumption that the following code is buggy, because the garbage collector might set the `a` field to null, before this `finalize` method can read it, thus preventing the method from attempting to cleanly dispose of the `Resource` in the `b` field  this all under the assertion that `safelyDispose` itself never throws:</div>

<div>







<blockquote><font face="'courier new', monospace"><span>public</span> <span>class</span> SomeService {<br> <span>private</span> <span>final</span> Resource <span>a</span>, <span>b</span>;<br>
<br> <span>public</span> SomeService(Resource a, Resource b) {<br>  <span>assert</span> a != <span>null</span> && b != <span>null</span>;<br>  <span>this</span>.<span>a</span> = a;<br>
  <span>this</span>.<span>b</span> = b;<br> }<br><span> </span>@Override<br> <span>protected</span> <span>void</span> finalize() <span>throws</span> Throwable {<br>
  <span>a</span>.safelyDispose();<br>  <span>b</span>.safelyDispose();<br> }<br>}</font></blockquote>Cheers,













</div><div>Chris</div>
<br>_______________________________________________<br>
Concurrency-interest mailing list<br>
<a href="mailto:Concurrency-interest@cs.oswego.edu">Concurrency-interest@cs.oswego.edu</a><br>
<a href="http://cs.oswego.edu/mailman/listinfo/concurrency-interest" target="_blank">http://cs.oswego.edu/mailman/listinfo/concurrency-interest</a><br>
<br></blockquote></div>