{"id":8389,"date":"2013-07-02T14:30:41","date_gmt":"2013-07-02T12:30:41","guid":{"rendered":"https:\/\/blog.trifork.com\/?p=8389"},"modified":"2013-07-02T14:30:41","modified_gmt":"2013-07-02T12:30:41","slug":"checking-return-values-in-java","status":"publish","type":"post","link":"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/","title":{"rendered":"Checking return values in Java"},"content":{"rendered":"<p>The other day I made a stupid coding error. It took me the better part of an hour to track it down. We all have those moments. Blame it on a bad night&#8217;s sleep, a brain fart, or perhaps the fact that your colleague at the next desk has been whistling that tune from Gotye&#8217;s &#8220;Somebody I used to know&#8221; (you know the one) all day, completely driving you crazy and taking your focus off your code.<br \/>\n<!--more--><\/p>\n<p>Anyway. Here&#8217;s my coding error:<\/p>\n<p><pre class=\"brush: java; gutter: true; title: ; notranslate\" title=\"\">&lt;br&gt;\n\/\/ If the finishedTest is an exam or a&lt;br&gt;\n\/\/ practiceTest, go to the next chapter or paragraph&lt;br&gt;\ngetNextChapterParagraph(chapters, taskContentIdentifier);&lt;br&gt;\nif (taskContentIdentifier == null) return null;&lt;br&gt;\nreturn new Task(taskContentIdentifier, Type.ASSESSMENT);&lt;br&gt;\n<\/pre><\/p>\n<p>And here&#8217;s the getNextChapterParagraph() method:<\/p>\n<p><pre class=\"brush: java; gutter: true; title: ; notranslate\" title=\"\">&lt;br&gt;\n\/**&lt;br&gt;\n * Returns the next paragraph or chapter given a list&lt;br&gt;\n * of chapters and the current chapter\/paragraph.&lt;br&gt;\n *\/&lt;br&gt;\nprivate ContentIdentifier getNextChapterParagraph(&lt;br&gt;\n    List&amp;lt;Chapter&amp;gt; chapters,&lt;br&gt;\n    ContentIdentifier contentIdentifier) {&lt;\/p&gt;\n&lt;p&gt;  \/\/ Do some stuff.....&lt;\/p&gt;\n&lt;p&gt;  return new ContentIdentifier(&lt;br&gt;\n    chapter.getStream().getId(),&lt;br&gt;\n    chapter.getContentId(),&lt;br&gt;\n    paragraph.getContentId());&lt;br&gt;\n}&lt;br&gt;\n<\/pre><\/p>\n<p>I&#8217;ve omitted and simplified some code to stick to the point, but I&#8217;m sure some of you have figured out what I did wrong by now. The <code>getNextChapterParagraph()<\/code> method doesn&#8217;t modify the <code>ContentIdentifier<\/code> instance passed as its second parameter; it returns a new one. <strong>Yet I wrote the calling code as if it did change the state of my <code>taskContentIdentifier<\/code>.<\/strong> D&#8217;oh!<\/p>\n<p>A more common case of this is calling methods on immutable objects, like <code>String<\/code>. For example:<\/p>\n<p><pre class=\"brush: java; gutter: true; title: ; notranslate\" title=\"\">&lt;br&gt;\nString string = &quot;this is a test&quot;;&lt;br&gt;\nstring.substring(10);\t\/\/ Bad!&lt;br&gt;\n<\/pre><\/p>\n<p>Now, of course, you can catch errors like this in your unit tests, which is how I found the error in the first place. But wouldn&#8217;t it be nice if there was some way to find out right when you make this mistake?<\/p>\n<h2>What&#8217;s wrong?<\/h2>\n<p><strong>So what exactly is wrong with the code above?<\/strong> Simply put: the <code>getNextChapterParagraph<\/code> (and <code>String.substring<\/code>) method&#8217;s sole purpose is to return a value; it doesn&#8217;t change the objects whose references were passed to it as parameters, and it doesn&#8217;t change the state of the object it&#8217;s a method of. In other words, it <em>has no side effects<\/em>. Because of this, if we call the method, we should always <em>do something<\/em> with the return value. If not, why did we call it in the first place? (There is actually one reason you might, but I&#8217;ll discuss this later on.)<\/p>\n<p>So we&#8217;d like to have the compiler or some tool warn us when we call a method that has no side effects, yet discard its return value. Any solution would have two parts:<\/p>\n<ol>\n<li><strong>Mark a method as having no side effects<\/strong> (perhaps it would be possible to determine by static analysis if a method has no side effects, but that&#8217;s a different blog post)<\/li>\n<li><strong>Warn when a method with no side effects is called and the return value is discarded<\/strong> (that is, not assigned to a variable, not used in an expression, and not passed to another method).<\/li>\n<\/ol>\n<h2>Enter: FindBugs and <code>@CheckReturnValue<\/code><\/h2>\n<p>As it turns out, FindBugs, the code analysis tool most of you are probably familiar with, has exactly the tools for this. I&#8217;ll describe how to set-up FindBugs in Eclipse further down. First, the solution to our problem: the <code>@CheckReturnValue<\/code> annotation. Simply put, <code>@CheckReturnValue<\/code> marks a method as having no side effects. If FindBugs then detects a method call to such a method where the return value is discarded, it emits a warning.<\/p>\n<p>To use <code>@CheckReturnValue<\/code> you&#8217;ll need the <code>findbugs-annotations.jar<\/code> on your classpath. Maven users can add the following dependency to their POM:<\/p>\n<p><pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;br&gt;\n&amp;lt;dependency&amp;gt;&lt;br&gt;\n  &amp;lt;groupId&amp;gt;findbugs&amp;lt;\/groupId&amp;gt;&lt;br&gt;\n  &amp;lt;artifactId&amp;gt;annotations&amp;lt;\/artifactId&amp;gt;&lt;br&gt;\n  &amp;lt;version&amp;gt;1.0.0&amp;lt;\/version&amp;gt;&lt;br&gt;\n&amp;lt;\/dependency&amp;gt;&lt;br&gt;\n<\/pre><\/p>\n<p>Example of using <code>@CheckReturnValue<\/code>:<\/p>\n<p><pre class=\"brush: java; gutter: true; title: ; notranslate\" title=\"\">&lt;br&gt;\npackage nl.trifork.examples.checkreturnvalue;&lt;\/p&gt;\n&lt;p&gt;import edu.umd.cs.findbugs.annotations.CheckReturnValue;&lt;\/p&gt;\n&lt;p&gt;public class StringHelper {&lt;\/p&gt;\n&lt;p&gt;\t@CheckReturnValue&lt;br&gt;\n\tpublic String shift(String str) {&lt;br&gt;\n\t\tif (str.length() &amp;lt; 2) return str;&lt;br&gt;\n\t\treturn str.substring(1) + str.charAt(0);&lt;br&gt;\n\t}&lt;br&gt;\n}&lt;br&gt;\n<\/pre><\/p>\n<p>Now, let&#8217;s try to call this method without using the return value:<\/p>\n<p><pre class=\"brush: java; gutter: true; title: ; notranslate\" title=\"\">&lt;br&gt;\npublic class CheckReturnValueExample {&lt;\/p&gt;\n&lt;p&gt;\tpublic void testStringHelper() {&lt;br&gt;\n\t\tStringHelper stringHelper = new StringHelper();&lt;br&gt;\n\t\tString str = &quot;string&quot;;&lt;br&gt;\n\t\tstringHelper.shift(str);&lt;br&gt;\n\t\t\/\/str = stringHelper.shift(str);&lt;br&gt;\n\t\tSystem.out.println(str);&lt;br&gt;\n\t}&lt;br&gt;\n}&lt;br&gt;\n<\/pre><\/p>\n<p>Running FindBugs yields the following warning:<\/p>\n<blockquote><p><strong>Bug<\/strong>: return value of StringHelper.shift(String) ignored in nl.trifork.examples.checkreturnvalue.CheckReturnValueExample.testStringHelper()<\/p><\/blockquote>\n<p>Now, we can&#8217;t annotate methods in JDK classes with <code>@CheckReturnValue<\/code>, but luckily FindBugs already seems to have checks for most common cases built-in:<\/p>\n<p><pre class=\"brush: java; gutter: true; title: ; notranslate\" title=\"\">&lt;br&gt;\npublic class CheckReturnValueExample {&lt;\/p&gt;\n&lt;p&gt;\tpublic void jdkStringExample() {&lt;br&gt;\n\t\tString str = &quot;this is a test&quot;;&lt;br&gt;\n\t\tstr.substring(10);&lt;br&gt;\n\t\tSystem.out.println(str);&lt;br&gt;\n\t}&lt;br&gt;\n}&lt;br&gt;\n<\/pre><\/p>\n<p>FindBugs:<\/p>\n<blockquote><p><strong>Bug<\/strong>: return value of String.substring(int) ignored in nl.trifork.examples.checkreturnvalue.CheckReturnValueExample.jdkStringExample()<\/p><\/blockquote>\n<h2>Exceptions<\/h2>\n<p>So are there any cases in which it is valid to discard the return value of a call to a side effect-less method? Actually, there is, but it stems from the fact that none except the most trivial of methods are truly without side effects. Consider <code>String.substring()<\/code>:<\/p>\n<blockquote>\n<h3>substring<\/h3>\n<pre>public <a title=\"class in java.lang\" href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/java\/lang\/String.html\">String<\/a> <b>substring<\/b>(int&nbsp;beginIndex)<\/pre>\n<p>Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.<\/p>\n<p>Examples:<\/p>\n<blockquote><p>\n<\/p><pre> \"unhappy\".substring(2) returns \"happy\"\n \"Harbison\".substring(3) returns \"bison\"\n \"emptiness\".substring(9) returns \"\" (an empty string)<\/pre>\n<\/blockquote>\n<p><strong>Parameters:<\/strong><\/p>\n<blockquote><p><code>beginIndex<\/code> &#8211; the beginning index, inclusive.<\/p><\/blockquote>\n<p><strong>Returns:<\/strong><\/p>\n<blockquote><p>the specified substring.<\/p><\/blockquote>\n<p><strong>Throws:<\/strong><\/p>\n<blockquote><p><code><a title=\"class in java.lang\" href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/java\/lang\/IndexOutOfBoundsException.html\">IndexOutOfBoundsException<\/a><\/code> &#8211; if <code>beginIndex<\/code> is negative or larger than the length of this <code>String<\/code> object.<\/p><\/blockquote>\n<\/blockquote>\n<p>Let&#8217;s say we wanted to write a unit test for substring testing that indeed passing a negative beginIndex causes an IndexOutOfBoundsException to be thrown:<\/p>\n<p><pre class=\"brush: java; gutter: true; title: ; notranslate\" title=\"\">&lt;br&gt;\n\t@Test(expected=IndexOutOfBoundsException.class)&lt;br&gt;\n\tpublic void testSubstring() {&lt;br&gt;\n\t\tString str = &quot;this is a test&quot;;&lt;br&gt;\n\t\tstr.substring(-1);&lt;br&gt;\n\t}&lt;br&gt;\n<\/pre><\/p>\n<p>If we run this through FindBugs, we get:<\/p>\n<blockquote><p><strong>Bug<\/strong>: return value of String.substring(int) ignored in nl.trifork.examples.checkreturnvalue.CheckReturnValueExample.testSubstring()<\/p><\/blockquote>\n<p>The long and short of this case is that, since we&#8217;re calling the method in a way it should never be in &#8220;normal&#8221; (non-testing) code (they&#8217;re called &#8220;exceptions&#8221; for a reason), this test class should not be run through FindBugs, or with a limited set of detectors enabled.<\/p>\n<h2>IDE integration<\/h2>\n<p>Now it&#8217;s all good and well to run FindBugs every once in a while to validate your code&#8217;s quality, but to catch these &#8220;check return value&#8221;-errors, you would need to be warned immediately, since by the time you would otherwise run FindBugs, you&#8217;d have already spent hours tracking down the bug. What we want is a FindBugs check <strong>everytime the incremental compiler runs<\/strong>. The FindBugs plugin for Eclipse can do exactly that.<\/p>\n<p>The easiest way to get the FindBugs plugin in Eclipse is to download the SpringSource Tool Suite, SpringSource&#8217;s version of the Eclipse IDE. On the Extensions page of the Dashboard view, you can select FindBugs, press Install, agree to the licence, press Next a few times and the Finish, and behold, after an Eclipse restart FindBugs is installed and ready to use.<\/p>\n<figure id=\"attachment_8427\" aria-describedby=\"caption-attachment-8427\" style=\"width: 606px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8427\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1.png\" alt=\"Installing the FindBugs plugin in the SpringSource Tool Suite\" width=\"606\" height=\"342\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1.png 606w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1-300x169.png 300w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><figcaption id=\"caption-attachment-8427\" class=\"wp-caption-text\">Installing the FindBugs plugin in the SpringSource Tool Suite<\/figcaption><\/figure>\n<p>The &#8220;plain vanilla&#8221; Eclipse users can add download site http:\/\/findbugs.cs.umd.edu\/eclipse and install the FindBugs feature. IntelliJ users: I&#8217;m sure you&#8217;ve already got FindBugs installed \ud83d\ude42<br \/>\nBy default FindBugs only runs when it&#8217;s launched from the Find Bugs context menu on a project or class. However, with a quick change you can get automatic FindBugs analysis every time your code is built automatically (usually when saving). Select your project, open up the project properties (Alt-Enter on *nix and Windows or \u2318I on Mac). Go to FindBugs in the left-hand panel. Then, check the &#8220;Run automatically&#8221; check box.<\/p>\n<figure id=\"attachment_8428\" aria-describedby=\"caption-attachment-8428\" style=\"width: 603px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8428\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/FindBugs-Run-automatically1.png\" alt=\"Enabling &quot;Run automatically&quot; in the FindBugs plugin\" width=\"603\" height=\"252\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2013\/06\/FindBugs-Run-automatically1.png 603w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2013\/06\/FindBugs-Run-automatically1-300x125.png 300w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2013\/06\/FindBugs-Run-automatically1-600x252.png 600w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><figcaption id=\"caption-attachment-8428\" class=\"wp-caption-text\">Enabling &#8220;Run automatically&#8221; in the FindBugs plugin<\/figcaption><\/figure>\n<p>Now, when you save your class file, FindBugs will run and you will see FindBugs warnings immediately in the gray &#8220;gutter&#8221; to the left of your source code:<\/p>\n<figure id=\"attachment_8423\" aria-describedby=\"caption-attachment-8423\" style=\"width: 433px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/FindBugs-warning.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8423\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/FindBugs-warning.png\" alt=\"A FindBugs warning\" width=\"433\" height=\"179\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2013\/06\/FindBugs-warning.png 433w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2013\/06\/FindBugs-warning-300x124.png 300w\" sizes=\"auto, (max-width: 433px) 100vw, 433px\" \/><\/a><figcaption id=\"caption-attachment-8423\" class=\"wp-caption-text\">A FindBugs warning<\/figcaption><\/figure>\n<p>Clicking the bug marker will open of the Bug Info panel with a description of the bug.<\/p>\n<figure id=\"attachment_8442\" aria-describedby=\"caption-attachment-8442\" style=\"width: 607px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8442\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/Bug-Info-panel1.png\" alt=\"The FindBugs Bug Info panel in Eclipse\" width=\"607\" height=\"475\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2013\/06\/Bug-Info-panel1.png 607w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2013\/06\/Bug-Info-panel1-300x235.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><figcaption id=\"caption-attachment-8442\" class=\"wp-caption-text\">The FindBugs Bug Info panel in Eclipse<\/figcaption><\/figure>\n<h2>Conclusion<\/h2>\n<p>Using the <code>@CheckReturnValue<\/code> annotation with FindBugs can warn you about forgetting to use a return value before you realize you forgot. So go, annotate all your side effect-less methods with <code>@CheckReturnValue<\/code> (that includes all those getter methods!) and make FindBugs a part of your regular build cycle. I know I will.<\/p>\n<p>On to better code!<\/p>\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bit.ly\/3BAo305\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"256\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png\" alt=\"\" class=\"wp-image-20303\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png 1024w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-300x75.png 300w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-768x192.png 768w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1536x384.png 1536w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-2048x512.png 2048w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1920x480.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>The other day I made a stupid coding error. It took me the better part of an hour to track it down. We all have those moments. Blame it on a bad night&#8217;s sleep, a brain fart, or perhaps the fact that your colleague at the next desk has been whistling that tune from Gotye&#8217;s [&hellip;]<\/p>\n","protected":false},"author":50,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[337,31],"tags":[11],"class_list":["post-8389","post","type-post","status-publish","format-standard","hentry","category-from-the-trenches","category-java","tag-java"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Checking return values in Java - Trifork Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Checking return values in Java - Trifork Blog\" \/>\n<meta property=\"og:description\" content=\"The other day I made a stupid coding error. It took me the better part of an hour to track it down. We all have those moments. Blame it on a bad night&#8217;s sleep, a brain fart, or perhaps the fact that your colleague at the next desk has been whistling that tune from Gotye&#8217;s [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Trifork Blog\" \/>\n<meta property=\"article:published_time\" content=\"2013-07-02T12:30:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1.png\" \/>\n<meta name=\"author\" content=\"Frans Flippo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Frans Flippo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/\",\"url\":\"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/\",\"name\":\"Checking return values in Java - Trifork Blog\",\"isPartOf\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1.png\",\"datePublished\":\"2013-07-02T12:30:41+00:00\",\"author\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/a3ee7a945951fa1cff33a723a2fc9621\"},\"breadcrumb\":{\"@id\":\"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/#primaryimage\",\"url\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1.png\",\"contentUrl\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/trifork.nl\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Checking return values in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/trifork.nl\/blog\/#website\",\"url\":\"https:\/\/trifork.nl\/blog\/\",\"name\":\"Trifork Blog\",\"description\":\"Keep updated on the technical solutions Trifork is working on!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/trifork.nl\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/a3ee7a945951fa1cff33a723a2fc9621\",\"name\":\"Frans Flippo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/75ba3422fb6b7c9dae6d833b934e3823?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/75ba3422fb6b7c9dae6d833b934e3823?s=96&d=mm&r=g\",\"caption\":\"Frans Flippo\"},\"url\":\"https:\/\/trifork.nl\/blog\/author\/fransf\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Checking return values in Java - Trifork Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Checking return values in Java - Trifork Blog","og_description":"The other day I made a stupid coding error. It took me the better part of an hour to track it down. We all have those moments. Blame it on a bad night&#8217;s sleep, a brain fart, or perhaps the fact that your colleague at the next desk has been whistling that tune from Gotye&#8217;s [&hellip;]","og_url":"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/","og_site_name":"Trifork Blog","article_published_time":"2013-07-02T12:30:41+00:00","og_image":[{"url":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1.png","type":"","width":"","height":""}],"author":"Frans Flippo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Frans Flippo","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/","url":"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/","name":"Checking return values in Java - Trifork Blog","isPartOf":{"@id":"https:\/\/trifork.nl\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/#primaryimage"},"image":{"@id":"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1.png","datePublished":"2013-07-02T12:30:41+00:00","author":{"@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/a3ee7a945951fa1cff33a723a2fc9621"},"breadcrumb":{"@id":"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/#primaryimage","url":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1.png","contentUrl":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2013\/06\/Install-FindBugs-STS1.png"},{"@type":"BreadcrumbList","@id":"https:\/\/trifork.nl\/blog\/checking-return-values-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/trifork.nl\/blog\/"},{"@type":"ListItem","position":2,"name":"Checking return values in Java"}]},{"@type":"WebSite","@id":"https:\/\/trifork.nl\/blog\/#website","url":"https:\/\/trifork.nl\/blog\/","name":"Trifork Blog","description":"Keep updated on the technical solutions Trifork is working on!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/trifork.nl\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/a3ee7a945951fa1cff33a723a2fc9621","name":"Frans Flippo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/75ba3422fb6b7c9dae6d833b934e3823?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/75ba3422fb6b7c9dae6d833b934e3823?s=96&d=mm&r=g","caption":"Frans Flippo"},"url":"https:\/\/trifork.nl\/blog\/author\/fransf\/"}]}},"_links":{"self":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/8389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/comments?post=8389"}],"version-history":[{"count":0,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/8389\/revisions"}],"wp:attachment":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/media?parent=8389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/categories?post=8389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/tags?post=8389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}