• Blog
  • Info Support
  • Career
  • Training
  • International Group
  • Info Support
  • Blog
  • Career
  • Training
  • International Group
  • Search
logo InfoSupport
  • Latest blogs
  • Popular blogs
  • Experts
      • Alles
      • Bloggers
      • Speakers
  • Meet us
  • About us
    • nl
    • en
    • .NET
    • Advanced Analytics
    • Agile
    • Akka
    • Alexa
    • Algorithms
    • Api's
    • Architectuur
    • Artificial Intelligence
    • ATDD
    • Augmented Reality
    • AWS
    • Azure
    • Big Data
    • Blockchain
    • Business Intelligence
    • Cloud
    • Code Combat
    • Cognitive Services
    • Communicatie
    • Containers
    • Continuous Delivery
    • CQRS
    • Cyber Security
    • Dapr
    • Data
    • Data & Analystics
    • Data Science
    • Data Warehousing
    • Databricks
    • DevOps
    • Digital Days
    • Docker
    • eHealth
    • Enterprise Architecture
    • Hacking
    • Infrastructure & Hosting
    • Innovatie
    • Integration
    • Internet of Things
    • Java
    • Machine Learning
    • Microservices
    • Microsoft
    • Microsoft Bot Framework
    • Microsoft Data Platform
    • Mobile Development
    • Mutation Testing
    • Open source
    • Pepper
    • Power BI
    • Privacy & Ethiek
    • Python
    • Quality Assistance & Test
    • Quality Assurance & Test
    • Requirements Management
    • Scala
    • Scratch
    • Security
    • SharePoint
    • Software Architecture
    • Software development
    • Software Factory
    • SQL Server
    • SSL
    • Start-up
    • Startup thinking
    • Stryker
    • Test Quality
    • Testing
    • TLS
    • TypeScript
    • Various
    • Web Development
    • Web-scale IT
    • Xamarin
    • Alles
    • Bloggers
    • Speakers
Home » Static code analysis in Eclipse 3.2: null reference checks
  • Static code analysis in Eclipse 3.2: null reference checks

    • By Peter Hendriks
    • Java 16 years ago
    • Java 0 comments
    • Java Java
    Static code analysis in Eclipse 3.2: null reference checks

    Static code analysis is a quick and easy way to automatically scan code for potential problems and improvements. The Eclipse compiler has some code analysis features. The latest milestone release (3.2 M5) contains a new feature: the null reference check. The null reference check can be enabled at the Java compiler options (disabled by default) and flags situations where a NullPointerException may occur. This is very useful! NullPointerExceptions are pretty serious bugs, and usually the null reference check spots other faults in the code logic as well. Let’s see some examples:

    First an easy one to get started. The foo method will always fail because bar is null. This error will always show up in any (unit) test with a nasty stack trace, and it is pretty obvious in the code that this is wrong.

    Lets do another one:

    This is a bit more interesting: either nothing happens(when bar is not null), or it crashes. The logic in the if-condition seems flawed: bar should NOT be null. Probably this is the intended behavior:

    That’s a lot better. Eclipse stops complaining, and the code actually works now.

    Let’s turn the previous examples around and see what happens:

    This is more subtle: the line above the if statement only executes properly when bar is not null. The if-condition is either unnecessary or the check for not-null is at the wrong spot. This code will work as long as bar is not null though, so
    in your initial test-run this problem might not be detected; in essence that makes this a potentially more evil bug than the ones above.

    One last situation for the Eclipse null-reference check:

    Similar to the problem above, this code will work as long as bar is not null. When bar is null, the method intends to print an error, but it should
    prevent the execution of the bar.toUpperCase() as well. Again a more subtle bug, you’ll be happy Eclipse catches them for you. 🙂

    The Eclipse null-reference analysis spots real and sometimes hard to find bugs in your code. Not ready to use Eclipse 3.2 M5 yet? Try the FindBugs plug-in or stand-alone analysis tools. Their latest version (0.9.5) actually works again when using it on larger projects, and has several other interesting static analysis checks to improve your code.

    Share this

Peter Hendriks

View profile

Related IT training

Go to training website

Related Consultancy solutions

Go to infosupport.com

Related blogs

  • Do you know Java? Care to prove it?

    Do you know Java? Care to prove it? Hanno Embregts - 4 months ago

  • Deploy je JDK 11 applicatie op je eigen Java 17 runtime

    Deploy je JDK 11 applicatie op je eigen Java 17 runtime Jelle Spoelders - 6 months ago

  • Explaining software development to a class of 6-year ol…

    Explaining software development to a class of 6-year ol… Hanno Embregts - 7 months ago

Related downloads

  • Beslisboom voor een rechtmatig ‘kopietje productie’

  • Klantreferentie: Remmicom zet wetgeving om in intellige…

  • Klantreferentie RDW: Samenwerken voor veilig en vertrou…

  • Klantreferentie BeFrank: Strategische IT voor een innov…

  • Wie durft te experimenteren met data in de zorg?

Related videos

  • mijnverzekeringenopeenrij.nl

    mijnverzekeringenopeenrij.nl

  • Winnaar | Innovation Projects 2017

    Winnaar | Innovation Projects 2017

  • Explore | Info Support & HAN & Poliskluis

    Explore | Info Support & HAN & Poliskluis

  • LifeApps bij HagaZiekenhuis

    LifeApps bij HagaZiekenhuis

  • Info Support | Bedrijfsfilm

    Info Support | Bedrijfsfilm

Nieuwsbrief

* verplichte velden

Contact

  • Head office NL
  • Kruisboog 42
  • 3905 TG Veenendaal
  • T +31 318 552020
  • Call
  • Mail
  • Directions
  • Head office BE
  • Generaal De Wittelaan 17
  • bus 30 2800 Mechelen
  • T +32 15 286370
  • Call
  • Mail
  • Directions

Follow us

  • Twitter
  • Facebook
  • Linkedin
  • Youtube

Newsletter

Sign in

Extra

  • Media Library
  • Disclaimer
  • Algemene voorwaarden
  • ISHBS Webmail
  • Extranet
Beheer cookie toestemming
Deze website maakt gebruik van Functionele en Analytische cookies voor website optimalisatie en statistieken.
Functioneel
Altijd actief
De technische opslag of toegang is strikt noodzakelijk voor het legitieme doel het gebruik mogelijk te maken van een specifieke dienst waarom de abonnee of gebruiker uitdrukkelijk heeft gevraagd, of met als enig doel de uitvoering van de transmissie van een communicatie over een elektronisch communicatienetwerk.
Voorkeuren
De technische opslag of toegang is noodzakelijk voor het legitieme doel voorkeuren op te slaan die niet door de abonnee of gebruiker zijn aangevraagd.
Statistieken
De technische opslag of toegang die uitsluitend voor statistische doeleinden wordt gebruikt. De technische opslag of toegang die uitsluitend wordt gebruikt voor anonieme statistische doeleinden. Zonder dagvaarding, vrijwillige naleving door uw Internet Service Provider, of aanvullende gegevens van een derde partij, kan informatie die alleen voor dit doel wordt opgeslagen of opgehaald gewoonlijk niet worden gebruikt om je te identificeren.
Marketing
De technische opslag of toegang is nodig om gebruikersprofielen op te stellen voor het verzenden van reclame, of om de gebruiker op een website of over verschillende websites te volgen voor soortgelijke marketingdoeleinden.
Beheer opties Beheer diensten Beheer leveranciers Lees meer over deze doeleinden
Voorkeuren
{title} {title} {title}