Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Product Lifecycle
  3. Free Tools
  4. Enforcing null-checks in Java/Android applications

Enforcing null-checks in Java/Android applications

Scheduled Pinned Locked Moved Free Tools
javaandroidhelphtmlapache
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13480875
    wrote on last edited by
    #1

    ## 1. Rationale Null references are considered to be one of the most expensive mistakes in IT design. It's not surprising that there are numerous efforts to solve it. Here are a couple of examples from the Java world: * Kotlin fights it at the language level * many tools try to report it as early as possible, for example, IntelliJ IDEA can be configured to [warn](https://www.jetbrains.com/help/idea/nullable-and-notnull-annotations.html) us about a possible NPE. Moreover, when the code below is compiled by the IDE, it automatically inserts null-checks, i.e. given the code snippet below ```java public void service(@NotNull String input) { // Process the input } ``` Resulting bytecode looks like if it's compiled from the following source: ```java public void service(@NotNull String input) { if (input == null) { throw new NullPointerException("Argument for @NotNull parameter 'input' must not be null"); } // Process the input } ``` *Kotlin* really solves the problem but *Java* is still a very popular language, so, we have to deal with nullable values. It's not always convenient to use *IntelliJ* build system for compiling sources to get that *null*-checks and the code which explicitly ensures preconditions via *checkNotNull()* or explicit *if (input == null) { throw new NullPointerException("") }* also looks not that appealing. More common setup is to configure a build through [*Gradle*](https://gradle.org/)/[*Maven*](http://maven.apache.org/)/[*Ant*](https://ant.apache.org/). It would not harm to get *IDE* tips on possible *null*-related problems and that auto-generated runtime checks without explicitly putting them into code. Current tool solves the second problem - it allows to add *null*-checks into *\*.class* files during compilation based on source code annotations. ## 2. License The project is licensed by MIT. ## 3. Design The whole project is based on a *Javac* extension. It plugs into the compilation process and automatically inserts *null*-checks into the resulting bytecode. That can be used either explicitly from the command line or from *Maven*/*Ant*. Also, there is a *Gradle* plugin which simplifie

    J 1 Reply Last reply
    0
    • U User 13480875

      ## 1. Rationale Null references are considered to be one of the most expensive mistakes in IT design. It's not surprising that there are numerous efforts to solve it. Here are a couple of examples from the Java world: * Kotlin fights it at the language level * many tools try to report it as early as possible, for example, IntelliJ IDEA can be configured to [warn](https://www.jetbrains.com/help/idea/nullable-and-notnull-annotations.html) us about a possible NPE. Moreover, when the code below is compiled by the IDE, it automatically inserts null-checks, i.e. given the code snippet below ```java public void service(@NotNull String input) { // Process the input } ``` Resulting bytecode looks like if it's compiled from the following source: ```java public void service(@NotNull String input) { if (input == null) { throw new NullPointerException("Argument for @NotNull parameter 'input' must not be null"); } // Process the input } ``` *Kotlin* really solves the problem but *Java* is still a very popular language, so, we have to deal with nullable values. It's not always convenient to use *IntelliJ* build system for compiling sources to get that *null*-checks and the code which explicitly ensures preconditions via *checkNotNull()* or explicit *if (input == null) { throw new NullPointerException("") }* also looks not that appealing. More common setup is to configure a build through [*Gradle*](https://gradle.org/)/[*Maven*](http://maven.apache.org/)/[*Ant*](https://ant.apache.org/). It would not harm to get *IDE* tips on possible *null*-related problems and that auto-generated runtime checks without explicitly putting them into code. Current tool solves the second problem - it allows to add *null*-checks into *\*.class* files during compilation based on source code annotations. ## 2. License The project is licensed by MIT. ## 3. Design The whole project is based on a *Javac* extension. It plugs into the compilation process and automatically inserts *null*-checks into the resulting bytecode. That can be used either explicitly from the command line or from *Maven*/*Ant*. Also, there is a *Gradle* plugin which simplifie

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      The above post should start with a link to the actual tool. Rest of the verbiage makes it difficult to find it and I think that the actual link doesn't even work.

      U 1 Reply Last reply
      0
      • J jschell

        The above post should start with a link to the actual tool. Rest of the verbiage makes it difficult to find it and I think that the actual link doesn't even work.

        U Offline
        U Offline
        User 13480875
        wrote on last edited by
        #3

        Thank you for the feedback! I've corrected the links. About the post organization - not sure that it would be better to give a link without explaining what the tool is. Regards, Denis

        J 1 Reply Last reply
        0
        • U User 13480875

          Thank you for the feedback! I've corrected the links. About the post organization - not sure that it would be better to give a link without explaining what the tool is. Regards, Denis

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          What I meant was that someone might quickly read the content or not even care and just want to look at the tool. So the link to the tool should be first followed by the existing content.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups