<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>The Object Teams Blog</title>
	<atom:link href="http://blog.objectteams.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.objectteams.org</link>
	<description>Everthing Object Teams - adding team spirit to your objects.</description>
	<pubDate>Sat, 12 May 2012 21:10:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Object Teams 2.1 Milestone 7 (finally) brings hot code replacement</title>
		<link>http://blog.objectteams.org/2012/05/object-teams-21-milestone-7-finally-brings-hot-code-replacement/</link>
		<comments>http://blog.objectteams.org/2012/05/object-teams-21-milestone-7-finally-brings-hot-code-replacement/#comments</comments>
		<pubDate>Sat, 12 May 2012 21:10:41 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[OTDT]]></category>

		<category><![CDATA[OTEquinox]]></category>

		<category><![CDATA[Object Teams]]></category>

		<category><![CDATA[debuggin]]></category>

		<category><![CDATA[pde]]></category>

		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=146</guid>
		<description><![CDATA[As part of the Juno Milestone 7 also Object Teams has delivered its Milestone 7.
As the main new feature in this milestone hot code replacement finally works when debugging OT/J or OT/Equinox applications.
What took us so long to make it work?


Well, hot code replacement didn&#8217;t work out of the box because our load-time weaver only [...]]]></description>
			<content:encoded><![CDATA[<p>As part of the Juno Milestone 7 also Object Teams has delivered its <a href="http://eclipse.org/objectteams/download.php#R21">Milestone 7</a>.</p>
<p>As the main new feature in this milestone <b>hot code replacement</b> finally works when debugging OT/J or OT/Equinox applications.</p>
<p>What took us so long to make it work?</p>
<ul>
<li>
Well, hot code replacement didn&#8217;t work out of the box because our load-time weaver only worked the first time each class was loaded. When trying to redefine a class in the VM the weaver was not called and thus class signatures could differ between the first loaded class and the redefined version. The VM would then reject the redefinition due to that signature change.
</li>
<li>
Secondly, we didn&#8217;t address this issue earlier, because I suspected this would be pretty tricky to implement. When I finally started to work on it, reality proved me wrong: the fix was actually pretty simple <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</li>
</ul>
<p>In fact the part that makes it work even in an Equinox setting is so generic that I <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=379342">proposed</a> to migrate the implementation into either Equinox or PDE/Debug, let&#8217;s see if there is interest.</p>
<p>Now when you debug any Object Teams application, your code changes can be updated live in the running debug target - no matter if you are changing teams, roles or base classes. Together with our already great <a href="http://help.eclipse.org/indigo/topic/org.eclipse.objectteams.otdt.doc/guide/debugging.html">debugging support</a>, this makes debugging Object Teams programs still faster.</p>
<p>More new features can be found in the <a href="http://www.eclipse.org/objectteams/pages/new_in_2.1.html">New&#038;Noteworthy</a> (accumulated since the Indigo release).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2012/05/object-teams-21-milestone-7-finally-brings-hot-code-replacement/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The message is the message</title>
		<link>http://blog.objectteams.org/2012/04/the-message-is-the-message/</link>
		<comments>http://blog.objectteams.org/2012/04/the-message-is-the-message/#comments</comments>
		<pubDate>Sun, 15 Apr 2012 00:53:13 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[null]]></category>

		<category><![CDATA[static analysis]]></category>

		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=145</guid>
		<description><![CDATA[I have been ranting about bad error messages, so in my own work, error messages better be helpful. At least I try.
As for the recent milestone 6 of the JDT a significant novelty was actually mostly about the wording of a few error/warning messages issued by the null analysis of the JDT compiler. We actually [...]]]></description>
			<content:encoded><![CDATA[<p>I have been ranting about <a title="No software can be better than its worst error message." href="http://blog.objectteams.org/2011/09/builds-are-like-real-software-or-even-more-so/">bad error messages</a>, so in my own work, error messages better be helpful. At least I try.</p>
<p>As for the recent milestone 6 of the JDT a significant novelty was actually mostly about the wording of a few error/warning messages issued by the <a href="http://wiki.eclipse.org/JDT_Core/Null_Analysis">null analysis of the JDT compiler</a>. We actually had <a title="bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=365859">quite a discussion</a> (no, I&#8217;m not expecting you to read all the comments in the bug:)).</p>
<p>Why did we go through all this instead of using the time to fix more bugs? Because the entire business of implementing more compiler warnings and in particular introducing annotation-based null analysis is to <b>help you to better understand possible weaknesses of your code</b>. This means our job isn&#8217;t done when the error message is printed on your screen, but only when you recognize why (and possibly how) your code could be improved.</p>
<p><center></p>
<table>
<tr>
<td>
So the game is:<br />when you see one of the new compiler messages <br /><a href="http://www.pinetree.net/humor/sherlockholmescamping.html">&#8220;what does it tell <b>you</b>?</a>&#8220;</td>
<td><a href="http://www.pinetree.net/humor/sherlockholmescamping.html"><img src="http://blog.objectteams.org/wp-uploads/2012/04/shsilhouette_question.jpg" alt="" title="It's elementary" width="98" height="125" class="alignnone size-full wp-image-140" /></a></td>
</tr>
</table>
<p></center></p>
<h3>Intended &#8220;inconsistency&#8221;</h3>
<p>Let&#8217;s start with an example that at first looks inconsistent:<br />
<a href='http://blog.objectteams.org/wp-uploads/2012/04/redundant-null-checks.png'><img src="http://blog.objectteams.org/wp-uploads/2012/04/redundant-null-checks.png" alt="" title="redundant-null-checks" class="aligncenter size-full wp-image-141" /></a></p>
<p>Both methods basically have the same code, still lines 14-17 are free of any warnings whereas the corresponding lines 24-27 have one warning and even an error. What does it tell us?</p>
<p>Here are some of the messages:</p>
<table cellpadding="5" style="margin-left:10px;background:gray;padding:1px;margin-top:-10px;margin-bottom:10px;">
<tr bgcolor="white">
<td>line 10</td>
<td>Redundant null check: The variable val1 cannot be null at this location</td>
</tr>
<tr bgcolor="white">
<td>line 12</td>
<td>Null comparison always yields false: The variable val1 cannot be null at this location</td>
</tr>
</table>
<p>Before bug 365859 the second method would show the same messages, giving no clue why after the initial start all the same code gives different results later. The initial improvement in that bug was to update the messages like this:</p>
<table cellpadding="5" style="margin-left:10px;background:gray;padding:1px;margin-top:-10px;margin-bottom:10px;">
<tr style="background:white;">
<td>line 20</td>
<td>Redundant null check: The variable val2 is specified as @NonNull</td>
</tr>
<tr style="background:white;">
<td>line 22</td>
<td>Null comparison always yields false: The variable val2 is specified as @NonNull</td>
</tr>
</table>
<p>Alright! Here lies the difference: in the first method, compiler warnings are based on the fact that we see an assignment with the non-null value <code>"OK"</code> and carefully follow each data-flow from there on. Non-null definitely holds until line 15, where potentially (depending on where <code>b</code> takes the control flow) <code>null</code> is assigned. Now the check in line 16 appears useful.</p>
<p>By contrast, the warnings in the second method tell us, that they are <b>not</b> based on flow analysis, but on the mere fact that <code>val2</code> is declared as of type <b><code>@NonNull String</code></b>. This specification is effectual, independent of location and flow, which has two consequences: now the assignment in line 25 is illegal; and since we can&#8217;t accept this assignment, line 26 still judges by the declaration of <code>val2</code> which says: <code>@NonNull</code>:</p>
<table cellpadding="5" style="margin-left:10px;background:gray;padding:1px;margin-top:-10px;margin-bottom:10px;">
<tr bgcolor="white">
<td>line 25</td>
<td>Null type mismatch: required &#8216;@NonNull String&#8217; but the provided value is null</td>
</tr>
<tr bgcolor="white">
<td>line 26</td>
<td>Redundant null check: The variable val2 is specified as @NonNull</td>
</tr>
</table>
<h3>Communicate the reasoning</h3>
<p>Three levels to a good error message:</p>
<ol>
<li>&#8220;You did wrong.&#8221;</li>
<li>&#8220;Your mistake was &#8230;&#8221;</li>
<li>&#8220;This is wrong because &#8230;&#8221;</li>
</ol>
<p>By now you probably know what I think of tools that answer using (1). To go from (2) towards (3) we split one particular error message into three. Look at this:<br />
<a href='http://blog.objectteams.org/wp-uploads/2012/04/nulltypemismatches.png'><img src="http://blog.objectteams.org/wp-uploads/2012/04/nulltypemismatches.png" alt="" title="null type mismatches" class="aligncenter size-full wp-image-142" /></a><br />
which gives these error messages:</p>
<table cellpadding="5" style="margin-left:10px;background:gray;padding:1px;margin-top:-10px;margin-bottom:10px;">
<tr style="background:white;">
<td>line 31</td>
<td>Null type mismatch: required &#8216;@NonNull String&#8217; but the provided value is null</td>
</tr>
<tr style="background:white;">
<td>line 32</td>
<td>Null type mismatch: required &#8216;@NonNull String&#8217; but the provided value is specified as @Nullable</td>
</tr>
<tr style="background:white;">
<td>line 34</td>
<td>Null type mismatch: required &#8216;@NonNull String&#8217; but the provided value is inferred as @Nullable</td>
</tr>
</table>
<p>Line 31 is obvious.</p>
<p>Line 32 is wrong <em>because</em> <code>in</code> is declared as <code>@Nullable</code>, saying <code>null</code> is a legal value for <code>in</code>, but since it&#8217;s not legal for <code>tmp2</code> the assignment is wrong.</p>
<p>In line 34 we are assigning a value that has no nullness specification; we say, <code>unknown</code> has a &#8220;legacy&#8221; type. From that alone the compiler cannot decide whether the assignment in line 34 is good. However, using also information from line 33 we can infer that <code>unknown</code> (probably) has type <code>@Nullable String</code>. In this particular case the inference is obvious, but the steps that lead to such conclusion can be arbitrarily complex.</p>
<p>What does this distinction tell you?</p>
<p>The error in line 31 is a plain violation of the specification: <code>tmp1</code> is required to be nonnull, but the assigment attempts to definitely break that rule.</p>
<p>The error in line 32 denotes the conflict between two contradictory declarations. We know nothing about actual runtime values, but we can tell without any doubt that the code violates a rule.</p>
<p>Errors of the type in line 34 are reported as a courtesy to the user: you didn&#8217;t say what kind of variable <code>unknown</code> is, thus normally the compiler would be reluctant to report problems regarding its use, but looking a bit deeper the compiler can infer some missing information. Only in this category it makes sense to discuss whether the conclusion is correct. The inference inside the compiler <em>might</em> be wrong (which would be a compiler bug).</p>
<h3>Sources of uncertainty</h3>
<p>Of the previous messages, only the one in line 31 mentions a runtime fact, the remaining errors only refer to possibilities of null values where no null value is allowed. In these cases the program might actually work - by accident. Just like this program <em>might</em> work:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">void</span> maybe<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">Object</span> val<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #000000; font-weight: normal">System</span>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span>val.<span style="color: #000000;">toUpperCase</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>While this is not a legal Java program, a hypothetical compiler <em>could</em> produce runnable byte code, and <em>if</em> the method is invoked with an argument that <em>happens</em> to be a String, all is well - by accident.</p>
<p>While we have no guarantee that things would break at runtime, we know for sure that some rule has been broken and thus the program is rejected.</p>
<p>The following method shows a different kind of uncertainty:<br />
<a href='http://blog.objectteams.org/wp-uploads/2012/04/uncheckednullnessconversion.png'><img src="http://blog.objectteams.org/wp-uploads/2012/04/uncheckednullnessconversion.png" alt="" title="unchecked nullness conversion" width="414" height="75" class="aligncenter size-full wp-image-143" /></a></p>
<p>What can we tell about this assignment? Well &#8230; we don&#8217;t know, it&#8217;s not definitely bad, but it&#8217;s not good either. What&#8217;s the problem? We need a <code>@NonNull</code> value, but we simply have no information whether <code>unspecified</code> can possibly be null or not. One of those legacy types again. After much back and forth we finally found that we have a precendent for this kind of problem: what&#8217;s the compiler say to this snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">void</span> safety2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">List</span> unspecified<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    List<span style="color: #000000;">&lt;</span>String<span style="color: #000000;">&gt;</span> strings <span style="color: #000000;">=</span> unspecified<span style="color: #000000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Right, it says:<br />
<code><br />
Type safety: The expression of type List needs unchecked conversion to conform to List<String><br />
</code><br />
meaning: we receive an argument with a type that lacks detailed specification, but we require such details on the left hand side of the assignment. Whether or not the RHS value matches the LHS requirement cannot be checked by the compiler. Argument <code>unspecified</code> has another kind of legacy type: a raw type. To gracefully handle the transition from legacy code to new code with more complete type specifications we only give a warning.</p>
<p>The same for null specifications:</p>
<table cellpadding="5" style="margin-left:10px;background:gray;padding:1px;margin-top:-10px;margin-bottom:10px;">
<tr style="background:white;">
<td>line 41</td>
<td>Null type safety: The expression of type String needs unchecked conversion to conform to &#8216;@NonNull String&#8217;</td>
</tr>
</table>
<p>In both cases, raw types and types lacking null specification, there are situations where ignoring this warning is actually OK: the legacy part of the code <em>may</em> be written in the full intention to conform to the rule (of only putting strings into the list / using only nonnull values), but was not able to express this in the expected style (with type parameters / null annotations). Maybe the information is still documented, e.g., in the javadoc. If you can convince yourself that the code plays by the rules although not declaring to do so: fine. But the compiler cannot check this, so it passes the responsibility to you, along with this warning.</p>
<h3>Tuning comiler messages</h3>
<p>If you buy into null annotations, the distinction of what is reported as an error vs warning should hopefully be helpful out of the box. Should you wish to change this, please do so with care. Ignoring some errors can render the whole business of null annotations futile. Still we hope that the correspondence between compiler messages and configuration options is clear:<br />
<a href='http://blog.objectteams.org/wp-uploads/2012/04/nullannotationoptions.png'><img src="http://blog.objectteams.org/wp-uploads/2012/04/nullannotationoptions.png" alt="" title="null-annotation options" class="aligncenter size-full wp-image-144" /></a></p>
<p>These options directly correspond to the messages shown above: </p>
<table cellpadding="5" style="margin-left:10px;background:#b0b0b0;padding:1px;margin-top:-10px;margin-bottom:10px;">
<tr>
<th>problems</th>
<th>controlled by this option</th>
</tr>
<tr style="background:white;">
<td>lines 31,32</td>
<td>Violation of null specification</td>
</tr>
<tr style="background:white;">
<td>line 34</td>
<td>Conflict between null annotations and null inference</td>
</tr>
<tr style="background:white;">
<td>line 39</td>
<td>Unchecked conversion from non-annotated type to @NonNull type</td>
</tr>
</table>
<h3>Conclusion</h3>
<p>The compiler does an awful lot of work trying to figure out whether your code makes sense, definitely, or maybe, or maybe not, or definitely not. We just decided, it should try a little harder to also <em>explain</em> its findings. Still, these messages are constrained to be short statements, so another part of the explanation is of course our job: to educate people about the background and rationale <em>why</em> the compiler gives the answers it gives.</p>
<p>I do hope you find the messages helpful, maybe even more so with a little background knowledge.</p>
<p>The next steps will be: what&#8217;s a good method for gradually applying null annotations to existing code? And during that process, what&#8217;s a good method for reacting to the compiler messages so that from throwing code at the compiler and throwing error messages back we move towards a fruitful <b>dialog</b>, with you as the brilliant Holmes and the compiler your loyal assistant Watson, just a bit quicker than the original, but that&#8217;s elementary.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2012/04/the-message-is-the-message/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using git for an interactive video - Replay the JDT tutorial</title>
		<link>http://blog.objectteams.org/2012/04/using-git-for-an-interactive-video-replay-the-jdt-tutorial/</link>
		<comments>http://blog.objectteams.org/2012/04/using-git-for-an-interactive-video-replay-the-jdt-tutorial/#comments</comments>
		<pubDate>Sat, 07 Apr 2012 14:20:15 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[Examples]]></category>

		<category><![CDATA[OTEquinox]]></category>

		<category><![CDATA[Object Teams]]></category>

		<category><![CDATA[EclipseCon]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[presentation]]></category>

		<category><![CDATA[quickfix]]></category>

		<category><![CDATA[slides]]></category>

		<category><![CDATA[static analysis]]></category>

		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=138</guid>
		<description><![CDATA[When preparing the tutorial How to train the JDT dragon, Ayushman and me packed way more material than we could possible teach in 3 hours time.
Luckily, Ayush came up with an idea that enables all of you to go through the exercise all on your own: instead of creating zip files with various stages of [...]]]></description>
			<content:encoded><![CDATA[<p>When preparing the <b>tutorial <a href="http://www.eclipsecon.org/2012/sessions/how-train-jdt-dragon">How to train the JDT dragon</a></b>, <a href="http://eclipseandjazz.blogspot.de/">Ayushman</a> and me packed way more material than we could possible teach in 3 hours time.</p>
<p>Luckily, Ayush came up with an idea that enables all of you to go through the exercise all on your own: instead of creating zip files with various stages of the example projects, we pushed everything to github. I apologize to those who were overwhelmed by how we pushed git onto the tutorial participants in Reston. </p>
<p>Now, as EclipseCon is over, here&#8217;s what you can do:</p>
<ul>
<li>Fetch the <b>slides</b>: <a href="http://www.eclipsecon.org/2012/sites/eclipsecon.org.2012/files/How%20To%20Train%20the%20JDT%20Dragon%20combined.pdf">PDF</a> or <a href="http://www.slideshare.net/aupsy/how-to-train-the-jdt-dragon">slideshare</a></li>
<li>Clone the <a href="http://github.com/aupsy/org.eclipsecon2012.jdt.tutorial">material for the plain JDT part</a> (<a href="git://github.com/aupsy/org.eclipsecon2012.jdt.tutorial">git: URL</a>), containing two projects for the first two exercises.
<ul>
<li><b>org.eclipsecon2012.jdt.tutorial1</b>: traverse the Java Model starting from the element selected in the UI</li>
<li><b>org.eclipsecon2012.jdt.quickFix1</b>: implement a quickfix for adding a missing null check</li>
</ul>
<li>Clone the <a href="http://github.com/aupsy/org.eclipsecon2012.misc.tutorial">misc repo</a> (<a href="git://github.com/aupsy/org.eclipsecon2012.misc.tutorial">git: URL</a>), containing
<ul>
<li><b>handouts</b>: instructions for the exercises</li>
<li><b>org.eclipsecon2012.jdt.populator</b>: plug-in that was used in the tutorial to create sample content in the runtime workbench; show cases how to programmatically create Java files from String content</li>
</ul>
</li>
<li>Clone the <a href="http://github.com/aupsy/org.eclipsecon2012.ot.tutorial">OT repo</a> (<a href="git://github.com/aupsy/org.eclipsecon2012.ot.tutorial">git: URL</a>), containing
<ul>
<li><b>AntiDemo</b>: the OT/Equinox hello-world: prohibition of class names starting with &#8220;Foo&#8221;.</li>
<li><b>Reachability</b>: a full blown reachability analysis in < 300 LOC.</li>
</ul>
</ul>
<p>The last exercise, &#8220;Reachability&#8221;, we couldn&#8217;t even show in Reston, but luckily this is the most detailed repo: in 13+1 commits I recorded the individual steps of adding inter-procedural reachability analysis piggy-back on top of the JDT compiler. If you replay these commits from the git repo you can watch me creating this little plug-in from scratch. Starting from step 5 you&#8217;ll be able to see the results when you fire up a runtime workbench: the analysis will print to stdout what methods it found during each full build.</p>
<p>Look at the commit comments which summarize what I would have explained in demo mode. Still the material is pretty dense as it explains three technologies at the same time:</p>
<ol>
<li>How does this analysis work?</li>
<li>What points in the JDT do we hook onto?</li>
<li>How is the integration achieved using Object Teams.</li>
</ol>
<p>Speaking of integration: using the &#8220;Binding Editor&#8221; you can see all bindings in a tabular view:<br />
<a href='http://blog.objectteams.org/wp-uploads/2012/04/reachabilitybindings.png'><img src="http://blog.objectteams.org/wp-uploads/2012/04/reachabilitybindings" alt="" title="Bindings of the Reachability plug-in" width="600" class="aligncenter size-medium wp-image-136" /></a><br />
The right hand side of the table give the full list of JDT elements we connect to:</p>
<ul>
<li>classes that are extended using a <img valign="middle" src="http://blog.objectteams.org/wp-uploads/2010/07/role_obj.png"> <b>role</b></li>
<li>methods/fields that are accessed externally via a <img  valign="middle" src="/wp-uploads/2011/03/calloutbinding_obj.gif"> <b>callout binding</b></li>
<li>methods that are intercepted using a <img valign="middle" src="/wp-uploads/2011/03/callinbindingafter_obj.gif">  <b>callin binding</b>.</li>
</ul>
<p>As a special bonus, step 14 in the git repo shows how to add problem markers for each unreachable method, so that the JDT will actually offer its existing quickfix for removing:<br />
<a href='http://blog.objectteams.org/wp-uploads/2012/04/unreachable.png'><img src="http://blog.objectteams.org/wp-uploads/2012/04/unreachable.png" alt="" title="Unreachable methods" width="500" height="237" class="aligncenter size-full wp-image-137" /></a><br />
(Yep, both methods are detected as unreachable: calling each other without being called from another reachable method doesn&#8217;t help).</p>
<p>I hope you enjoy playing with the examples. For questions please use one of the forums:</p>
<ul>
<li><a href="http://www.eclipse.org/forums/index.php/f/13/">JDT</a></li>
<li><a href="http://www.eclipse.org/forums/index.php/f/157/"/>Object Teams</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2012/04/using-git-for-an-interactive-video-replay-the-jdt-tutorial/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Thanks Eclipse!!</title>
		<link>http://blog.objectteams.org/2012/03/thanks-eclipse/</link>
		<comments>http://blog.objectteams.org/2012/03/thanks-eclipse/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 02:53:52 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=135</guid>
		<description><![CDATA[Wow! I&#8217;m totally flattered. Last night I received this shiny trophy:



Basically, my involvement in Eclipse has two simple reasons:

Given that the JDT is the favorite IDE of so many smart Java developers, it&#8217;s a real treat to be able to take part in its constant improvement still. Making unsolicited comments to other components of the [...]]]></description>
			<content:encoded><![CDATA[<p>Wow! I&#8217;m totally flattered. Last night I received this <a href="http://www.eclipse.org/org/press-release/20120326_awardwinners.php">shiny trophy</a>:</p>
<p><center><br />
<a href='http://blog.objectteams.org/wp-uploads/2012/03/eclipsecon2012_award_270.png'><img src="http://blog.objectteams.org/wp-uploads/2012/03/eclipsecon2012_award_270.png" alt="" title="eclipsecon2012_award_270" width="270" height="295" class="alignnone size-medium wp-image-134" /></a><br />
</center></p>
<p>Basically, my involvement in Eclipse has two simple reasons:</p>
<ul>
<li>Given that the JDT is the favorite IDE of so many smart Java developers, it&#8217;s a real treat to be able to take part in its constant improvement still. Making unsolicited comments to other components of the bunch just adds to the fun.</li>
<li>Given the success of Java and the JDT, it&#8217;s a thrill to lift both of them to new dimensions in the <a href="http://www.eclipse.org/objectteams">Object Teams project</a>. Have a deep look and you&#8217;ll think differently about objects and modularity.</li>
</ul>
<p>If you feel similarly in any regard but aren&#8217;t involved yet, don&#8217;t feel shy: none of the Eclipse components is to be worshiped in a museum, but all over the place new contributors are essential for keeping this great piece of software fresh and alive in its second decade. I&#8217;m looking forward to next years Top Contributor! (Yet, I will not pass on my little trophy :)).</p>
<p>Thanks to all, and especially to the JDT team, for having me!</p>
<p>BTW: EclipseCon 2012 in Reston is the best EclipseCon 2012 ever!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2012/03/thanks-eclipse/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Help the JDT Compiler helping you! - 3: The essence of null annotations</title>
		<link>http://blog.objectteams.org/2012/02/help-the-jdt-compiler-helping-you-3-the-essence-of-null-annotations/</link>
		<comments>http://blog.objectteams.org/2012/02/help-the-jdt-compiler-helping-you-3-the-essence-of-null-annotations/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 19:39:08 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[analysis]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[null]]></category>

		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=133</guid>
		<description><![CDATA[After my little excursion to detecting resource leaks let me return to our favorite bug: NPE.



Basic support for null annotations was big news at the release of the Eclipse SDK Juno M4.
To fully understand the approach it&#8217;s good to sit back and think of what exactly we&#8217;re telling the compiler when we add null annotations [...]]]></description>
			<content:encoded><![CDATA[<p>After my little excursion to <a href="http://blog.objectteams.org/2012/02/help-the-jdt-compiler-helping-you-2-resource-leaks-continued/">detecting</a> <a href="http://blog.objectteams.org/2012/01/help-the-jdt-compiler-helping-you-1-resource-leaks/">resource leaks</a> let me return to our favorite bug: NPE.<br />
<center><br />
<img src="http://blog.objectteams.org/wp-uploads/2011/01/nonpe.png"  width="64"/><br />
</center></p>
<p>Basic support for null annotations was big news at the release of the <a href="http://download.eclipse.org/eclipse/downloads/drops4/S-4.2M4-201112092100/eclipse-news-M4.html">Eclipse SDK Juno M4</a>.</p>
<p>To fully understand the approach it&#8217;s good to sit back and think of what exactly we&#8217;re telling the compiler when we add null annotations to a program.</p>
<h2>Annotations as filters</h2>
<p>One could certainly use the annotations to mean the following:</p>
<dl>
<dt><code>@NonNull</code></dt>
<dd style="margin-left:20px;"><em>&#8220;I don&#8217;t think this variable will ever hold a null, no need to warn me, when I dereference that value.&#8221;</em></dd>
<dt><code>@Nullable</code></dt>
<dd style="margin-left:20px;"><em>&#8220;I guess this variable could be null, so please warn me when I forget a null check before dereferencing.&#8221;</em></dd>
</dl>
<p><br/></p>
<p>Interpreted in this way, the annotations would already be helpful, and actually this would rank them in the same category as <code>@SuppressWarnings("null")</code>: no matter what the compiler analyzed up-to this point, please take my word that this thing is / is not dangerous. In both cases we&#8217;d ask the compiler to look at certain things and ignore others, because we &#8220;know better&#8221;.</p>
<p>However, telling the compiler what&#8217;s dangerous and what&#8217;s not puts the cart before the horse. If I do so, <strong>I</strong> will be the weakest link in the chain of analysis. I could err, I <em>do</em> err - that&#8217;s why I have NPEs in the first place, so I shouldn&#8217;t tell the compiler to trust my judgment.</p>
<p>The good news is: when used appropriately null annotations provide a lot more help.</p>
<h2>Annotations as an extension of the type system</h2>
<h3>The essence of static typing</h3>
<p>Lets step back and imagine Java wouldn&#8217;t have static typing. A variable declaration would be nothing more than a name, introduced -say- using an imaginary keyword <code>var</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;">   var o<span style="color: #000000;">;</span>
   o <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> Person<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
   o.<span style="color: #000000;">meow</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span></pre></div></div>

<p>Right, we could now assign any object, any value, to the variable <code>o</code> and on the other hand we could attempt to invoke any method. Only at runtime will we notice whether the object refered to by <code>o</code> actually has a method <code>meow()</code>. Obviously, this code is unsafe, it could abort saying &#8220;Message on understood&#8221;. As Java programmers we don&#8217;t accept this unsafety, so we use types as a specification:</p>
<div style="margin:15px;margin-bottom:10px;background-color:#def4fe;border: 2px solid #c4c295;padding:5px;">
<strong>A typed variable declaration adds a specification with these two sides:</strong></p>
<ul>
<li>It adds a <strong>constraint</strong> such that only certain values can legally be assigned to the variable</li>
<li>It establishes a <strong>guarantee</strong> that certain operations are well-defined wrt the value of the variable.</li>
</ul>
</div>
<p>A statically typed language forces a decision: what values do I want to allow to be bound to the variable? If I declare <code>o</code> as of type <code>Cat</code> the compiler can conclude that &#8220;<code>o = new Person();</code>&#8221; violates the constraint and cannot be accepted. If, OTOH, I declared <code>o</code> as of type <code>Person</code> the compiler won&#8217;t complain at the assignment but typically it will not find a <code>meow()</code> method in a class <code>Person</code> so that line is now illegal. Only if all things match: the declaration, the assignment, and the usage of a variable, only then will the compiler accept the program and certify that this program will not raise &#8220;Message not understood&#8221;. It&#8217;s a trade: constraint for guarantee.<br />
In a statically typed language we are constrained in what we can say, but we gain the guarantee that a certain kind of error will not occur at runtime.</p>
<p>Sounds fair?</p>
<h3>More constraints - more guarantees</h3>
<p>Standard static typing constrains the program such that values match to the operations we perform with these values, except - there&#8217;s a big loop-hole: in traditional object-oriented type systems each class type contains a value that is <strong>not</strong> suitable for most operations: the value <code>null</code>, which <a href="http://en.wikipedia.org/wiki/Tony_Hoare">Tony Hoare</a> called his <a href="http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare">&#8220;billion dollar mistake&#8221;</a>.</p>
<p>At a closer look, static type checking in Java is founded on a contradiction:</p>
<ul>
<li>When analyzing an assignment assume that <code>null</code> is a legal value for every object type.</li>
<li>When looking at a method call / a field reference assume that <code>null</code> cannot occur (otherwise no unchecked dereference could be considered as legal).</li>
</ul>
<p>This is exactly, what null annotations fix: they split each traditional object type into two types:</p>
<dl>
<dt><code>@NonNull Cat</code></dt>
<dd style="margin-left:20px;">This is the type that contains only cat values</dd>
<dt><code>@Nullable Cat</code></dt>
<dd style="margin-left:20px;">This is the union of the above type and the null-type which contains only one value: <code>null</code></dd>
</dl>
<p><br/></p>
<p>You can read the type <code>@Nullable Cat</code> as: either a cat or null.</p>
<h3>Null warnings vs. type errors</h3>
<p>Those users who try the new feature in the JDT may be surprised to see a whole new kind of error messages. While the original goal is to get alerted about potential NPEs, the compiler may now complain with messages like:</p>
<div style="margin:15px;margin-bottom:10px;background-color:#def4fe;border: 2px solid #c4c295;padding:5px;">
<img valign="middle" src="http://blog.objectteams.org/wp-uploads/2012/01/error_obj.gif"/> Type mismatch: required &#8216;@NonNull Cat&#8217; but the provided value can be null
</div>
<p>The question may arise, why this is reported as an error, even if no NPE can be directly caused at the statement in question. The answer can be deduced from the following analogy:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">void</span> foo<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">Object</span> o, @Nullable Cat c<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    Cat aCat <span style="color: #000000;">=</span> o<span style="color: #000000;">;</span>                 <span style="color: #3F7F5F; font-style: italic;">// &quot;Type mismatch: cannot convert from Object to Cat&quot;</span>
    @NonNull Cat reallyACat  <span style="color: #000000;">=</span> c<span style="color: #000000;">;</span> <span style="color: #3F7F5F; font-style: italic;">// &quot;Type mismatch: required '@NonNull Cat' but the provided value can be null.&quot;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><em>(The wording of the second message will be still improved to better reflect different kinds of RHS values).</em></p>
<p>The analogy shows:</p>
<ul>
<li>The assignment itself could actually succeed, and even if types don&#8217;t match, a language without static typing could actually accept both assignments.</li>
<li>If, however, the assignment were accepted, all subsequent analysis of the use of this variable is useless, because the assumption about the variable&#8217;s type may be broken.</li>
</ul>
<p>Therefor, a first step towards making NPE impossible is to be strict about these rules. Assigning a value to a @NonNull variable without being able to prove that the value is not null is illegal. Just as assigning an Object value to a Cat variable without being able to prove that the value is indeed a cat is illegal.</p>
<p>Interestingly, for the first assignment, Java offers a workaround:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;">    Cat aCat <span style="color: #000000;">=</span> <span style="color: #000000;">&#40;</span>Cat<span style="color: #000000;">&#41;</span> o<span style="color: #000000;">;</span></pre></div></div>

<p>Using the cast operator has two implications: we tell the compiler that we &#8220;know better&#8221;, that <code>o</code> is actually a cat (we do believe so) and secondly, as compiler and JVM cannot fully trust our judgment a check operation will be generated that will raise a ClassCastException if our assumption was wrong.</p>
<p>Can we do something similar for @NonNull conversion? Without the help of JSR 308 we cannot use annotations in a cast, but we can use a little helper:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">void</span> foo<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">Object</span> o, @Nullable Cat c<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    @NonNull Cat reallyACat  <span style="color: #000000;">=</span> assertNonNull<span style="color: #000000;">&#40;</span>c<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #000000;">&#125;</span>
@NonNull <span style="color: #000000;">&lt;</span>T<span style="color: #000000;">&gt;</span> T assertNonNull<span style="color: #000000;">&#40;</span>T val<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #7F0055; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>val <span style="color: #000000;">==</span> <span style="color: #7F0055; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #7F0055; font-weight: bold;">throw</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">NullPointerException</span><span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;NonNull assertion violated&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
    <span style="color: #7F0055; font-weight: bold;">return</span> val<span style="color: #000000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><em>corrected on 2012/03/05</em></p>
<p>What? We deliberately throw an NPE although the value isn&#8217;t even dereferenced? Why that?</p>
<p>The helper mimics exactly what a cast does for normal type conversions: check if the given value conforms to the required type. If not, raise an exception. If the check succeeds re-type the value to the required type.</p>
<p>Here&#8217;s an old school alternative:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;"><span style="color: #7F0055; font-weight: bold;">void</span> foo<span style="color: #000000;">&#40;</span>@Nullable Cat c<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    @SuppressWarnings<span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;null&quot;</span><span style="color: #000000;">&#41;</span> @NonNull Cat reallyACat  <span style="color: #000000;">=</span> c<span style="color: #000000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>(Requires that you enable using @SuppressWarnings for optional errors).</p>
<p>Which approach is better? Throwing an exception as soon as something unexpected happens is far better than silencing the warning and waiting for it to explode sometime later at some other location in the code. The difference is felt during debugging. It&#8217;s about <strong>blame assignment</strong>.<br />
If things blow up at runtime, I want to know which part of the code caused the problem. If I use @SuppressWarnings that part is in stealth mode, and an innocent part of the code will get the blame when it uses the wrong-typed value.</p>
<p>Remember, however, that cast and assertNonNull are not the solution, those are workarounds. Solutions must explicitly perform the check and provide application specific behavior to both outcomes of the check. Just as a cast without an instanceof check is still a land-mine, so is the use of the above helper: NPE can still occur. If you need to dereference a variable that&#8217;s not @NonNull you should really ask yourself:</p>
<ul>
<li>How can it happen that I end up with a null value in this position?</li>
<li>How can the application safely and soundly continue in that situation?</li>
</ul>
<p>These questions cannot be answered by any tool, these relate to the <em>design</em> of your software.</p>
<h2>Help the JDT compiler helping you</h2>
<p>This post showed you two things you can and should do to help the compiler helping you:</p>
<p>Add null annotations to resolve the contradiction that&#8217;s inherent in Java&#8217;s type system: a type can only either contain the value null or not contain the value null. Still Java&#8217;s type system opportunistically assumes a little bit of both. With annotations you can resolve the ambiguity and state which of the two possible types you mean.</p>
<p>Second, listen to the new type error messages. They&#8217;re fundamental to the analysis. If you disregard (or even disable) these messages there&#8217;s no point in letting the analysis apply all its sophisticated machinery. From false assumptions we cannot conclude anything useful.</p>
<p>If you apply these two hints, the compiler will be your friend and report quite some interesting findings. For a project that uses null annotations right from the first line of code written, this advice should be enough. The difficult part is: if you have a large existing code base already, the compiler will have a lot to complain. Think of migrating a fully untyped program to Java. You bet you could use some more help here. Let&#8217;s talk about that in future posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2012/02/help-the-jdt-compiler-helping-you-3-the-essence-of-null-annotations/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Help the JDT Compiler helping you! - 2: Resource leaks - continued</title>
		<link>http://blog.objectteams.org/2012/02/help-the-jdt-compiler-helping-you-2-resource-leaks-continued/</link>
		<comments>http://blog.objectteams.org/2012/02/help-the-jdt-compiler-helping-you-2-resource-leaks-continued/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 20:11:17 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[analysis]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=132</guid>
		<description><![CDATA[In my previous post I showed the basics of a new analysis that I originally introduced in the JDT compiler as of 3.8 M3 and improved for M5. This post will give yet more insight into this analysis, which should help you in writing code that the compiler can understand.
Flow analysis - power and limitation
An [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://blog.objectteams.org/2012/01/help-the-jdt-compiler-helping-you-1-resource-leaks/">previous post</a> I showed the basics of a new analysis that I originally introduced in the JDT compiler as of 3.8 M3 and improved for M5. This post will give yet more insight into this analysis, which should help you in writing code that the compiler can understand.</p>
<h3>Flow analysis - power and limitation</h3>
<p>An advantage of implementing leak analysis in the compiler lies in the synergy with the existing flow analysis. We can precisely report whether a resource allocation is <strong>definitely</strong> followed by a <code>close()</code> or if <strong>some execution paths</strong> exist, where the <code>close()</code> call is by-passed or an early exit is taken (return or due to an exception). This is pretty cool, because it shows exactly those corner cases in your implementation, that are so easy to miss otherwise.</p>
<p>However, this flow analysis is only precise if each resource is uniquely bound to one local variable. Think of declaring all resource variables as <code>final</code>. If that is possible, our analysis is excellent, if you have multiple assignments to the same variable, if assignments happen only on some path etc, then our analysis can only do a best-effort attempt at keeping track of your resources. As a worst case consider this:</p>

<div class="wp_syntax"><div class="code"><pre class="otj" style="font-family:monospace;">  <span style="color: #000000; font-weight: normal">Reader</span> r <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">FileReader</span><span style="color: #000000;">&#40;</span>f<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
  <span style="color: #000000; font-weight: normal">Reader</span> r2 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">null</span><span style="color: #000000;">;</span>
  <span style="color: #7F0055; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>goOn<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
     <span style="color: #7F0055; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>hasMoreContent<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        readFrom<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
     <span style="color: #000000;">&#125;</span> <span style="color: #7F0055; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
        r.<span style="color: #000000;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> <span style="color: #3F7F5F; font-style: italic;">// close is nice, but which resource exactly is being closed??</span>
     <span style="color: #000000;">&#125;</span>
     <span style="color: #7F0055; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>maybe<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        r2 <span style="color: #000000;">=</span> r<span style="color: #000000;">;</span>
     <span style="color: #000000;">&#125;</span>             <span style="color: #3F7F5F; font-style: italic;">// at this point: which resource is bound to r2??</span>
     <span style="color: #7F0055; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>hasMoreFiles<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        r <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">FileReader</span><span style="color: #000000;">&#40;</span>getFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> <span style="color: #3F7F5F; font-style: italic;">// wow, we can allocate plenty of resources in a loop</span>
     <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
  <span style="color: #7F0055; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>r2 <span style="color: #000000;">!=</span> <span style="color: #7F0055; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
    r2.<span style="color: #000000;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span></pre></div></div>

<p>This code <em>may</em> even be safe, but there&#8217;s no way our analysis can keep track of how many resources have been allocated in the loop, and which of these resources will be closed. Which one is the resource flowing into <code>r2</code> to be closed at the end? We don&#8217;t know. So if you want the compiler to help you, pretty please, avoid writing this kind of code <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So what rules should you follow to get on terms with the compiler? To understand the mentioned limitation it helps to realize that our analysis is mostly connected to local variables, keeping some status bits for each of them. However, when analyzing variables the analysis has <strong>no notion of values</strong>, i.e., in the example the compiler can only see one variable <code>r</code> where at runtime an arbitrary number of Reader <strong>instances</strong> will be allocated, bound and dropped again.</p>
<p>Still, there are three special situations which the analysis can detect:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="otj" style="font-family:monospace;">  <span style="color: #000000; font-weight: normal">Reader</span> r <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">FileReader</span><span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;someFile&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
  r <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">FileReader</span><span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;otherFile&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
  r <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">BufferedReader</span><span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
  <span style="color: #000000; font-weight: normal">Reader</span> r2 <span style="color: #000000;">=</span> getReader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
  <span style="color: #7F0055; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>r2 <span style="color: #000000;">!=</span> <span style="color: #7F0055; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
     r2.<span style="color: #000000;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
  <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<ol>
<li>In line 2 we&#8217;re leaking the instance from line 1, because after the assignment we no longer have a reference to the first reader and thus we cannot close it.</li>
<li>However, line 3 is safe, because the same reader that is being dropped from <code>r</code> is first wrapped into a new <code>BufferedReader</code> and indirectly via that wrapper it is still reachable.</li>
<li>Finally at the end of the example snippet, the analysis can see that <code>r2</code> is either <code>null</code> or closed, so all is safe.</li>
</ol>
<p>You see the compiler understands actually a lot of the semantics. </p>
<p>My fundamental advice is:</p>
<div style="margin:15px;margin-bottom:10px;text-align:center;background-color:#def4fe;border: 2px solid #c4c295;padding:5px;">
If the compiler warns about leaking resources and if you think the warning is unnecessary, try to better explain why you think so, first of all by <strong>using exactly one local variable per resource.</strong>
</div>
<h3>Resource ownership</h3>
<p>Still not every method lacking a <code>close()</code> call signifies a resource leak. For an exact and definite analysis we would need one more piece of information: who <strong>owns</strong> any given resource?</p>
<p>Consider a group of methods happily passing around some resources among themselves. For them the same happens as for groups of people: <strong>diffusion of responsibility</strong>:</p>
<blockquote><p>Well, no, I really thought that <em>you</em> were going to close this thing?!!?&#8221;.</p></blockquote>
<p>If we had a notion of <strong>ownership</strong> we&#8217;d simple require the unique owner of each resource to eventually close that resource. However, such advanced concepts, while thoroughly explored in academia, are lacking from Java. To mitigate this problem, I made the following approximations of an ownership model:</p>
<ol>
<li>If a method allocates a resource, <strong style="color:green;">it owns it</strong> - initially.</li>
<li>If a method obtains a resource by calling another method, it <strong style="color:blue;">may potentially be responsible</strong>, since we cannot distinguish ownership from lending</li>
<li>If a method passes a resource as an argument to another method (or constructor), it <strong style="color:blue;">may or may not transfer ownership</strong> by this call.</li>
<li>If a method receives a resource as a parameter, it <strong style="color:red">assumes the caller is probably still responsible</strong></li>
<li>If a method passes a resource as its return value back to the caller, <strong style="color:red">it rejects any responsibility</strong></li>
<li>If a resource is ever stored in a field, <strong style="color:red">no single method feels responsible</strong>.</li>
<li>If a resource is wrapped in an array <strong style="color:blue">we can no longer track</strong> the resource, but maybe the current method is still responsible?
</ol>
<p>In this list, <strong style="color:green;">green</strong> means: the compiler is encouraged to report anything fishy as a bug. <strong style="color:blue;">Blue</strong> means, we still do the reporting, but weaken the message by saying &#8220;Potential resource leak&#8221;. <strong style="color:red">Red</strong> means, the compiler is told to shut up because this code could only be checked by whole system analysis (which is not feasible for an incremental compiler).</p>
<p>The advice that follows from this is straight-forward:</p>
<div style="margin:15px;margin-bottom:10px;text-align:center;background-color:#def4fe;border: 2px solid #c4c295;padding:5px;">Keep the responsibility for any resource local.<br/>Do not pass it around and don&#8217;t store it in fields.<br/>Do not talk to any strangers about your valuable resources!
</div>
<p>In this regard, unclean code will actually cancel the leak analysis. If ownership of a resource is unclear, the compiler will just be quiet. So, do you think we should add a warning to signal whenever this happens? Notably, a warning when a resource is stored in a field?</p>
<h3>The art of being quiet</h3>
<p>Contrary to naive thinking, the art of good static analysis is not in reporting <em>many</em> issues. The art is in making yourself heard. If the compiler just rattles on with lots of uninteresting findings, no one will listen, no one will <em>have the capacity</em> to listen to all that.</p>
<p>A significant part of the work on resource leak analysis has gone into making the compiler quieter. And of course this is not just a matter of turning down the volume, but a matter of much smarter judgment of what the user might be interested in hearing.</p>
<p>By way of two recently resolved bugs (<a title="Bug 358903 - Filter practically unimportant resource leak warnings" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=358903">358903</a> and <a title ="Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=368546">368546</a>) we managed to reduce the number of resource leak warnings reported against the sources of the Eclipse SDK from almost 100 down to 8. Calling this a great success may sound strange at first, but that it is.</p>
<p>At the level we reached now, I can confidently encourage everybody to enable this analysis (my recommendation: resource leaks = error, potential resource leaks = warning). The &#8220;Resource leak&#8221; problems indeed deserve a closer look, and also the potential ones could give valuable hints.</p>
<p>For each issue reported by the compiler you have three options:</p>
<ol>
<li>Agree that this is a bug</li>
<li>Explain to the compiler why you believe the code is safe (unique assignment to locals, less passing around)</li>
<li>Add <code>@SuppressWarnings("resource")</code> to tell the compiler that you know what you are doing.</li>
</ol>
<p>But remember the nature of responsibility: if you say you don&#8217;t want to here any criticism you&#8217;d better be really sure. If you say you take the responsibility the compiler will be the humble servant who quietly forgets all worries.</p>
<p>Finally, if you are in the lucky position to use Java 7 for your projects, do the final step: enable &#8220;Resource not managed with try-with-resource&#8221; analysis. This was actually the start of this long journey: to let the compiler give hints where this new syntax would help to make your code safer and to make better visible <em>why</em> it is safe - with respect to resource leaks.</p>
<p>Final note: one of the bugs mentioned above was only resolved today. So with M5 you will still see some avoidable false positives. The next build from now should be better <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;ll be back, soon, with more on our favorite exception: NPE.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2012/02/help-the-jdt-compiler-helping-you-2-resource-leaks-continued/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Help the JDT Compiler helping you! - 1: Resource Leaks</title>
		<link>http://blog.objectteams.org/2012/01/help-the-jdt-compiler-helping-you-1-resource-leaks/</link>
		<comments>http://blog.objectteams.org/2012/01/help-the-jdt-compiler-helping-you-1-resource-leaks/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 14:25:14 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[analysis]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=131</guid>
		<description><![CDATA[During the Juno cycle a lot of work in the JDT has gone into more sophisticated static analysis, and some more is still in the pipe-line. I truly hope that once Juno is shipped this will help all JDT users to find more bugs immediately while still typing. However, early feedback regarding these features shows [...]]]></description>
			<content:encoded><![CDATA[<p>During the Juno cycle a lot of work in the JDT has gone into more sophisticated static analysis, and some more is still in the pipe-line. I truly hope that once Juno is shipped this will help all JDT users to find more bugs immediately while still typing. However, early feedback regarding these features shows that users are starting to expect miracles from the analysis <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>On the one hand seeing this is flattering, but on the other hand it makes me think we should perhaps explain what exactly the analysis can see and what is beyond its vision. If you take a few minutes learning about the concepts behind the analysis you&#8217;ll not only understand its limitations, but more importantly you will learn how to write code that&#8217;s better readable - in this case for reading by the compiler. Saying: with only slightly rephrasing your programs you can help the compiler to better understand what&#8217;s going on, to the effect that the compiler can answer with much more useful error and warning messages.</p>
<p>Since there&#8217;s a lot of analysis in this JDT compiler I will address just one topic per blog post. This post goes to improvements in the detection of resource leaks.</p>
<h2>Resource leaks - the basics</h2>
<p>Right when everybody believed that Eclipse Indigo RC 4 was ready for the great release, another <a href="http://dev.eclipse.org/mhonarc/lists/cross-project-issues-dev/msg06246.html">blocker bug</a> was detected: a simple resource leak basically prevented Eclipse from launching on a typical Linux box if more than 1000 bundles are installed. Coincidentally, at the same time the JDT team was finishing up work on the new try-with-resources statement introduced in Java 7. So <a href="http://blog.objectteams.org/2011/06/a-use-case-for-java-7/">I was thinking</a>: shouldn&#8217;t the compiler help users to migrate from notoriously brittle handling of resources to the new construct that was designed specifically to facilitate a safe style of working with resources?</p>
<h3>What&#8217;s a resource?</h3>
<p>So, how can the compiler know about resources? Following the try-with-resources concept, any instance of type <code>java.lang.AutoCloseable</code> is a resource. Simple, huh? In order to extend the analysis also to pre Java 7 code, we also consider <code>java.io.Closeable</code> (available since 1.5).</p>
<h3>Resource life cycle</h3>
<p>The expected life cycle of any resource is : <em>allocate&mdash;use&mdash;close</em>. Simple again. </p>
<p>From this we conclude the code pattern we have to look for: where does the code allocate a closeable and no call to close() is seen afterwards. Or perhaps a call is seen but not all execution paths will reach that call, etc.</p>
<h3>Basic warnings</h3>
<p>With <a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.8M3-201110271800/eclipse-news-M3.html#JDT-resource-leaks">Juno M3</a> we released a <a href="http://blog.deepakazad.com/2011/10/detecting-resource-leaks-with-eclipse.html">first analysis</a> that could now tell you things like:</p>
<ul style="list-style:none;">
<li><img valign="middle" src="http://blog.objectteams.org/wp-uploads/2012/01/error_obj.gif"/> Resource leak: &#8220;input&#8221; is never closed
<li><img valign="middle" src="http://blog.objectteams.org/wp-uploads/2012/01/error_obj.gif"/> Resource leak: &#8220;input&#8221; is never closed at this location (<em>if a method exit happens before reaching close()</em>)
</ul>
<p>If the problem occurs only on some execution paths the warnings are softened (saying &#8220;potential leak&#8221; etc.).</p>
<p>Good, <strong>but</strong>&#8230;</p>
<h2>Signal to noise - part 1</h2>
<p>It turned out that the analysis was causing significant noise. How come? The concepts are so clear and all code that wouldn&#8217;t exhibit the simple <em>allocate&mdash;use&mdash;close</em> life cycle should indeed by revised, shouldn&#8217;t it?</p>
<p>In fact we found several patterns, where these warnings were indeed useless.</p>
<h3>Resource-less resources</h3>
<p>We learned that not every subtype of <code>Closeable</code> really represents a resource that needs leak prevention. How many times have you invoked <code>close()</code> on a <code>StringWriter</code>, e.g.? Just have a look at its implementation and you&#8217;ll see why this isn&#8217;t worth the effort. Are there more classes in this category?</p>
<p>Indeed we found a total of 7 classes in <code>java.io</code> that purely operate on Java objects without allocating any resources from the operating system:</p>
<ul>
<li><code>StringReader</code></li>
<li><code>StringWriter</code></li>
<li><code>ByteArrayInputStream</code></li>
<li><code>ByteArrayOutputStream</code></li>
<li><code>CharArrayReader</code></li>
<li><code>CharArrayWriter</code></li>
<li><code>StringBufferInputStream</code></li>
</ul>
<p>For none of these does it make sense to warn about missing <code>close()</code>.</p>
<p>To account for these classes we simply added a <strong>white list</strong>: if a class is in the list suppress any warnings/errors. This white list consists of exactly those 7 classes listed above. Sub-classes of these classes are not considered.</p>
<h3>Wrapper resources</h3>
<p>Another group of classes implementing <code>Closeable</code> showed up, that are not strictly resources themselves. Think of <code>BufferedInputStream</code>! Does it need to be closed?</p>
<p>Well? What&#8217;s your answer? The correct answer is: it depends. A few examples:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="otj" style="font-family:monospace;">	<span style="color: #7F0055; font-weight: bold;">void</span> wrappers<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: normal">String</span> content<span style="color: #000000;">&#41;</span> <span style="color: #7F0055; font-weight: bold;">throws</span> <span style="color: #000000; font-weight: normal">IOException</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #000000; font-weight: normal">Reader</span> r1, r2, r3, r4<span style="color: #000000;">;</span>
		r1 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">BufferedReader</span><span style="color: #000000;">&#40;</span><span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">FileReader</span><span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;someFile&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		r2 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">BufferedReader</span><span style="color: #000000;">&#40;</span><span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">StringReader</span><span style="color: #000000;">&#40;</span>content<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		r3 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">FileReader</span><span style="color: #000000;">&#40;</span><span style="color: #2A00ff;">&quot;somefile&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		r4 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000000; font-weight: normal">BufferedReader</span><span style="color: #000000;">&#40;</span>r3<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		r3.<span style="color: #000000;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>How many leaks? With same added smartness the compiler will signal only one resource leak: on <code>r1</code>. All others are safe: </p>
<ul>
<li><code>r2</code> is a wrapper for a resource-less closeable: no OS resources are ever allocated here.</li>
<li><code>r3</code> is explicitly closed</li>
<li><code>r4</code> is just a wrapper around <code>r3</code> and since that is properly closed, <code>r4</code> does not hold onto any OS resources at the end.</li>
<li>returning to <code>r1</code>, why is that a leak? It&#8217;s a wrapper, too, but now the underlying resource (a <code>FileReader</code>) is not directly closed so it&#8217;s the responsibility of the wrapper and can only be triggered by calling <code>close()</code> on the wrapper <code>r1</code>.</li>
</ul>
<p><strong style="color:red;">EDIT:</strong> We are not <em>recommending</em> to close a wrapped resource directly as done with <code>r3</code>, closing the wrapper (<code>r4</code>) is definitely cleaner, and when wrapping a <code>FileOutputStream</code> with a <code>BufferedOutputStream</code> closing the former is actually <em>wrong</em>, because it may lose buffered content that hasn&#8217;t been flushed. However, the analysis is strictly focused on <em>resource leaks</em> and for analysing wrappers we narrow that notion to leaks of <em>OS resources</em>. For the given example, reporting a warning against <code>r4</code> would be pure noise.</p>
<p>Summarizing: wrappers don&#8217;t directly hold an OS resource, but delegate to a next closeable. Depending on the nature and state of the nested closeable the wrapper may or may not be responsible for closing. In arbitrary chains of wrappers with a relevant resource at the bottom, closing any closeable in the chain (including the bottom) will suffice to release the single resource. If a wrapper chain is not properly closed the problem will be flagged against the outer-most wrapper, since calling <code>close()</code> at the wrapper will be delegated along all elements of the chain, which is the cleanest way of closing.</p>
<p>Also for wrappers the question arises: how does the compiler know? Again we set up a <strong>white list</strong> with all wrapper classes we found in the JRE: 20 classes in <code>java.io</code>, 12 in <code>java.util.zip</code> and 5 in other packages (the full lists are in <a href="http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tree/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java">TypeConstants.java</a>, search for &#8220;_CLOSEABLES&#8221;).</p>
<h2>Status and outlook</h2>
<p>Yes, <a href="http://inhabitat.com/wp-content/blogs.dir/1/files/2012/01/costa-concordia-fuel-spill-1-537x356.jpg">a leak can be a stop-ship problem</a>.</p>
<p>Starting with Juno M3 we have basic analysis of resource leaks; starting with Juno M5 the analysis uses the two white lists mentioned above: resource-less closeables and resource wrappers. In real code this significantly reduces the number of false positives, which means: for the remaining warnings the signal-to-noise ratio is significantly better.</p>
<p>M5 will actually bring more improvements in this analysis, but that will be subject of a next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2012/01/help-the-jdt-compiler-helping-you-1-resource-leaks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A little statistics of the day</title>
		<link>http://blog.objectteams.org/2012/01/a-little-statistics-of-the-day/</link>
		<comments>http://blog.objectteams.org/2012/01/a-little-statistics-of-the-day/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 18:27:14 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=129</guid>
		<description><![CDATA[My latest query in Eclipse&#8217;s bugzilla answered 189 bugs.
Out of these a certain TLA was mentioned just in the bug summaries 54 times.
Additionally, the long form of the same word occurred 5 times.
Those who have followed my previous posts, know which three letters I&#8217;m referring to. Looks like they&#8217;re even more relevant in some Eclipse [...]]]></description>
			<content:encoded><![CDATA[<p>My latest query in Eclipse&#8217;s bugzilla answered <strong>189 bugs</strong>.</p>
<p>Out of these a certain TLA was mentioned just in the bug summaries <strong>54 times</strong>.<br />
Additionally, the long form of the same word occurred <strong>5 times</strong>.</p>
<p>Those who have followed my previous posts, know which three letters I&#8217;m referring to. Looks like they&#8217;re even more relevant in some Eclipse components than I ever fancied (no - not telling, in which component I searched <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2012/01/a-little-statistics-of-the-day/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Object Teams with Null Annotations</title>
		<link>http://blog.objectteams.org/2011/12/object-teams-with-null-annotations/</link>
		<comments>http://blog.objectteams.org/2011/12/object-teams-with-null-annotations/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 21:32:14 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[OTDT]]></category>

		<category><![CDATA[Object Teams]]></category>

		<category><![CDATA[analysis]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[EclipseCon]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[modularity]]></category>

		<category><![CDATA[null]]></category>

		<category><![CDATA[presentation]]></category>

		<category><![CDATA[product line]]></category>

		<category><![CDATA[release]]></category>

		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=128</guid>
		<description><![CDATA[The recent release of Juno M4 brought an interesting combination: The Object Teams Development Tooling now natively supports annotation-based null analysis for Object Teams (OT/J). How about that? 
  
The path behind us
Annotation-based null analysis has been added to Eclipse in several stages:

Using OT/J for prototyping
As discussed in this post, OT/J excelled once more [...]]]></description>
			<content:encoded><![CDATA[<p>The recent release of <a href="http://www.eclipse.org/downloads/index-developer.php">Juno M4</a> brought an interesting combination: The <a href="http://www.eclipse.org/objectteams">Object Teams</a> <a href="http://wiki.eclipse.org/Object_Teams_Development_Tooling">Development Tooling</a> now natively supports annotation-based null analysis for Object Teams <a href="http://wiki.eclipse.org/OTJ">(OT/J)</a>. How about that? <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<center><img src="http://blog.objectteams.org/wp-uploads/2011/01/nonpe.png" alt="NO NPE" title="NO NPE" width="64" height="64"/>  <img src="http://www.eclipse.org/objectteams/images/ot_64n.png" /></center></p>
<h3>The path behind us</h3>
<p><a href="http://wiki.eclipse.org/JDT_Core/Null_Analysis">Annotation-based null analysis</a> has been added to Eclipse in several stages:</p>
<dl>
<dt style="font-weight:bold;">Using OT/J for prototyping</dt>
<dd style="margin-left:15px;margin-bottom:5px;">As discussed in <a href="http://blog.objectteams.org/2011/03/null-annotations-prototyping-without-the-pain/">this post</a>, OT/J excelled once more in a complex development challenge: it solved the conflict between extremely tight integration and separate development without double maintenance. That part was real fun.</dd>
<dt style="font-weight:bold;">Applying the prototype to numerous platforms</dt>
<dd style="margin-left:15px;margin-bottom:5px;">Next I <a href="http://blog.objectteams.org/2011/08/mix-n-match-language-support/">reported</a> that only one binary deployment of the OT/J-based prototype sufficed to upgrade any of 12 different versions of the JDT to support null annotations &#8212; looks like a cool product line</dd>
<dt style="font-weight:bold;">Pushing the prototype into the JDT/Core</dt>
<dd style="margin-left:15px;margin-bottom:5px;">Next all of the JDT team (<a href="http://www.eclipse.org/projects/project.php?id=eclipse.jdt.core">Core</a> and <a href="http://www.eclipse.org/projects/project.php?id=eclipse.jdt.ui">UI</a>) invested efforts to make the new feature an integral part of the JDT. Thanks to all for this great collaboration!</dd>
<dt style="font-weight:bold;">Merging the changes into the OTDT</dt>
<dd style="margin-left:15px;margin-bottom:5px;">Now, that the new stuff was mixed back into the plain-Java implementation of the JDT, it was no longer applicable to other variants, but the routine merge between JDT/Core HEAD and Object Teams automatically brought it back for us. With the <a href="http://www.eclipse.org/objectteams/download.php#R21">OTDT 2.1 M4</a>, annotation-based null analysis is integral part of the OTDT.</dd>
</dl>
<h3 style="margin-top:20px;">Where we are now</h3>
<p>Regarding the JDT, others like <a href="http://www.jroller.com/andyl/entry/no_more_npe_s">Andrey</a>, <a href="http://blog.deepakazad.com/2011/12/annotation-based-null-analysis-with-jdt.html">Deepak</a> and <a href="http://eclipseandjazz.blogspot.com/2011/12/inter-procedural-null-analysis-using.html">Aysush</a> have beaten me in blogging about the new coolness. It seems the feature even made it to become a <a href="http://jaxenter.com/eclipse-juno-3-8-4-2-edges-ever-closer-with-milestone-4-39780.html">top mention</a> of the <a href="http://download.eclipse.org/eclipse/downloads/drops4/S-4.2M4-201112092100/eclipse-news-M4.html">Eclipse SDK Juno M4</a>. Thanks for spreading the word!</p>
<p>Ah, and thanks to <a href="http://www.fosslc.org">FOSSLC</a> you can now watch my <a title="Bye, bye, NPE, at ECE 2011" href="http://www.fosslc.org/drupal/content/bye-bye-npe">ECE 2011 presentation</a> on this topic.</p>
<h3>Two problems of OOP, and their solutions</h3>
<p>Now, OT/J with null annotations is indeed an interesting mix, because it solves two inherent problems of object-oriented programming, which couldn&#8217;t differ more:</p>
<p><b>1.: NullPointerException</b> is the most widespread and most <b>embarrassing bug</b> that we produce day after day, again and again. Pushing support for null annotations into the JDT has one major motivation: if you use the JDT but don&#8217;t use null annotations <b>you&#8217;ll no longer have an excuse</b>. For no good reasons your code will retain these miserable properties:</p>
<ul>
<li>It <b>will throw</b> those embarrassing NPEs.</li>
<li>It doesn&#8217;t tell the reader about fundamental <b>design decisions</b>: which part of the code is <b>responsible</b> for handling which potential problems?</li>
</ul>
<p>Why is this problem inherent to OOP? The dangerous operator that causes the exception is this:<br />
<center style="margin:-5px;"><a href='http://blog.objectteams.org/wp-uploads/2011/12/npddot.png'><img width="550" src="http://blog.objectteams.org/wp-uploads/2011/12/npddot.png" alt="" title="The DOT" class="aligncenter size-medium wp-image-126" /></a></center><br />
right, the tiny little <b>dot</b>. And that happens to be the least dispensable operator in OOP.</p>
<p><b>2.: Objectivity</b> seems to be a central property on any approach that is based just on <b>Objects</b>. While so many other activities in software engineering are based on the insight that complex problems with many stakeholders involved can best be addressed using <b>perspectives</b> and <b>views</b> etc., OOP forces you to abandon all that: an object is an object is an object. Think of a very simple object: a File. Some part of the application will be interested in the content so it can decode the bytes and do s.t. meaningful with it, another part of the application (maybe an underlying framework) will mainly be interested in the path in the filesystem and how it can be protected against concurrent writing, still other parts don&#8217;t care about either but only let you send the thing over the net. By representing the &#8220;File&#8221; as an object, that object must have <b>all properties</b> that are relevant to <b>any part</b> of the application. It must be openable, lockable and sendable and whatnot. This yields bloated objects and unnecessary, sometimes daunting dependencies. Inside the object all those different use cases it is involved in can not be separated!</p>
<p>With <b>roles</b> objectivity is replaced by a disciplined form of <b>subjectivity</b>: each part of the application will see the object with exactly those properties it needs, mediated by a specific role. New parts can add new properties to existing objects &#8212; but not in the unsafe style of dynamic languages, but strictly typed and checked. What does it mean for practical design challenges? E.g, direct support for feature oriented designs - the direct path to painless product lines etc.</p>
<p>Just like the dot, objectivity seems to be hardcoded into OOP. While null annotations make the dot safe(r), the roles and teams of OT/J add a new dimension to OOP where perspectives can be used directly in the implementation. Maybe it does make sense, to have both capabilities in one language <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> although one of them cleans up what should have been sorted out many decades ago while the other opens new doors towards the future of sustainable software designs.</p>
<h3>The road ahead</h3>
<p>The work on null annotations goes on. What we have in M4 is usable and I can only encourage adopters to start using it right now, but we still have an ambitious goal: eventually, the null analysis shall not only find <em>some</em> NPEs in your program, but eventually the absense of null related errors and warnings shall give the developer the guarantee that this piece of code <b>will never throw NPE at runtime</b>.</p>
<p>What&#8217;s missing towards that goal:</p>
<ol>
<li><b>Fields</b>: we don&#8217;t yet support <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649">null annotations for fields</a>. This is next on our plan, but one particular issue will require experimentation and feedback: how do we handle the initialization phase of an object, where fields start as being null? More on that soon.</li>
<li><b>Libraries</b>: we want to support <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=331651">null specifications for libraries</a> that have no null annotations in their source code.</li>
<li><b>JSR 308</b>: only with JSR 308 will we be able to annotate <b>all</b> occurrences of types, like, e.g., the element type of a collection (think of <code>List<@NonNull String></code>)</li>
</ol>
<p>Please stay tuned as the feature evolves. Feedback including bug reports is very welcome!</p>
<p>Ah, and one more thing in the future: I finally have the opportunity to work out a cool tutorial with a fellow JDT committer: <a href="http://www.eclipsecon.org/2012/sessions/how-train-jdt-dragon">How To Train the JDT Dragon</a> with Ayushman. Hope to see y&#8217;all in Reston!</p>
<p><a href='http://blog.objectteams.org/wp-uploads/2011/12/130x100_speaking_ecna12.gif'><img src="http://blog.objectteams.org/wp-uploads/2011/12/130x100_speaking_ecna12.gif" alt="" title="130x100_speaking_ecna12" width="130" height="100" class="alignnone size-full wp-image-127" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2011/12/object-teams-with-null-annotations/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Essence of Object Teams</title>
		<link>http://blog.objectteams.org/2011/09/the-essence-of-object-teams/</link>
		<comments>http://blog.objectteams.org/2011/09/the-essence-of-object-teams/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 14:39:14 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[Examples]]></category>

		<category><![CDATA[Object Teams]]></category>

		<category><![CDATA[dimensions]]></category>

		<category><![CDATA[modularity]]></category>

		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://blog.objectteams.org/?p=125</guid>
		<description><![CDATA[When I write about Object Teams and OT/J I easily get carried away indulging in cool technical details. Recently in the Object Teams forum we were asked about the essence of OT/J which made me realize that I had neglected the high-level picture for a while. Plus: this picture looks a bit different every time [...]]]></description>
			<content:encoded><![CDATA[<p>When I write about Object Teams and OT/J I easily get carried away indulging in cool technical details. Recently in the <a href="http://www.eclipse.org/forums/index.php/f/157/">Object Teams forum</a> we were asked about the essence of OT/J which made me realize that I had neglected the high-level picture for a while. Plus: this picture looks a bit different every time I look at it, so here is today&#8217;s answer in two steps: short and extended.</p>
<p><u>Short version:</u></p>
<div style="margin:15px;margin-bottom:10px;text-align:center;background-color:#def4fe;border: 2px solid #c4c295;padding:5px;">
<strong>OT/J adds to OO the capability to define a program in terms of multiple <em>perspectives</em>.<br />
</strong></div>
<p><u>Extended version:</u></p>
<p>In software design, e.g., we are used to describing a system from multiple perspectives or views, like: structural vs. behavioral views, architectural vs. implementation views, views focusing on distribution vs. business logic, or just: one perspective per use case.<br />
<img src="http://upload.wikimedia.org/wikipedia/commons/8/81/UML_Diagrams.jpg"/><br />
A collage of UML diagrams</br><br />
&copy; 2009, <a href="http://en.wikipedia.org/wiki/User:Kishorekumar_62">Kishorekumar 62</a>, licensed under the <a href="http://en.wikipedia.org/wiki/en:Creative_Commons">Creative Commons</a> <a href="http://creativecommons.org/licenses/by-sa/3.0/deed.en">Attribution-Share Alike 3.0 Unported</a> license.</p>
<p>In regular OO programming this is not well supported, an object is defined by exactly one class and no matter from which perspective you look at it, it always has the exact same properties. The best we can do here is controlling the visibility of methods by means of interfaces.</p>
<div align=center>
<a href='http://blog.objectteams.org/wp-uploads/2011/09/oneclass2.png'><img src="http://blog.objectteams.org/wp-uploads/2011/09/oneclass2.png" alt="" title="one class" class="aligncenter size-full wp-image-121" /></a></p>
<div style="margin-top:-15px; margin-bottom:15px;">
A person is a person is a person!?
</div>
</div>
<p>By contrast, in OT/J you start with a set of lean base objects and then you may attach specific roles for each perspective. Different use cases and their scenarios can be implemented by different roles. Visualization in the UI may be implemented by another independent set of roles, etc.</p>
<div align=center>
<a href='http://blog.objectteams.org/wp-uploads/2011/09/basewithroles2.png'><img src="http://blog.objectteams.org/wp-uploads/2011/09/basewithroles2.png" alt="" title="base with roles" class="alignnone size-full wp-image-122" /></a></p>
<div style="margin-top:-15px; margin-bottom:15px;">
A base seen from multiple perspectives via roles.
</div>
</div>
<h3>Code-level comparison?</h3>
<p>I&#8217;ve been asked to compare standard OO and OT/J by direct comparison of code examples, but I&#8217;m not sure if it is a good idea to do, because OT/J is not intended to just provide a nicer syntax for things you can do in the same way using OO. OT/J - as any serious new programming language should do IMHO - wants you to <strong>think</strong> differently about your design. For example, we can give an educational implementation of the <a href="http://wiki.eclipse.org/OTExample_Observer">Observer pattern using OT/J</a>, but once you &#8220;think Object Teams&#8221; you may not be interested in the Observer pattern any more, because you can achieve basically the same effect using a single callin binding as shown in our <a href="http://wiki.eclipse.org/OTExample_Stopwatch">Stopwatch example</a>.</p>
<p>So, positively speaking, OT/J wants you to think in terms of perspectives and make the perspectives you would naturally use for describing the system explicit by means of roles.</p>
<p>OTOH, a new language is of course only worth the effort if you have a <strong>problem</strong> with existing approaches. The problems OT/J addresses are inherently difficult to discuss in small examples, because they are:</p>
<ol>
<li><strong>software complexity</strong>, e.g., with standard OO finding a suitable decomposition where different concerns are not badly tangled with each other becomes notoriously difficult.</li>
<li><strong>software evolution</strong>, e.g., the initial design will be challenged with change requests that no-one can foresee up-front.</li>
</ol>
<p>(<em>Plus all the other <a href="http://blog.objectteams.org/2011/03/combination-of-concerns/">concerns addressed</a></em>)</p>
<p>Both, theory and experience, tell me that OT/J excels in both fields. If anyone wants to challenge this claim using your own example, please do so and post your findings, or lets discuss possible designs together.</p>
<h3>One more essential concept</h3>
<p>I should also mention the second essence in OT/J: after slicing elements of your program into roles and base objects we also support to <strong>re-group</strong> the pieces in a meaningful way: as <strong>roles are contained in teams</strong>, those teams enable you to raise the level of abstraction such that each user-relevant feature, e.g., can be captured in exactly one team, hiding all the details inside. As a result, for a high-level design view you no longer have to look at diagrams of hundreds of classes but maybe just a few tens of teams.</p>
<p>Hope this helps seeing the big picture. Enough hand-waving for today, back to the code! <img src='http://blog.objectteams.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectteams.org/2011/09/the-essence-of-object-teams/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

