JDK-8061401 : Non-null types
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Priority: P4
  • Status: Closed
  • Resolution: Other
  • Submitted: 2004-12-13
  • Updated: 2014-10-17
  • Resolved: 2014-10-17
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
As java doesn't has references (only pointers), the most common errors I've seen so far is NullPointerException. So the suggestion is simple either to have reference types like "String& " or keyword notnull..

so I can write either:

public void doSomething(String& s) { }

or

public void doSomething(notnull String s){}

and be sure that nobody will pass me a null pointer. The first syntax is more regular and natural, while the second is more java like :)


JUSTIFICATION :
It will make code maintenance easier, and make NullPointerException really exceptional rather than regular.
###@###.### 2004-12-13 23:35:06 GMT

Comments
The 'specification' component of the Java Bug System is for reporting technical errors and ambiguities in the text of The Java Language Specification and The JVM Specification. It is not the venue to propose new features in the Java language or JVM. Ongoing feature development is carried out in OpenJDK (http://openjdk.java.net/jeps/); corresponding enhancements to The Java Language Specification and The JVM Specification are managed through the Java Community Process (http://jcp.org/).
17-10-2014

EVALUATION Java does infact have references. However, what C++ calls references is known as aliases and Java doesn't support that. Please submit a separate RFE for aliasing if desired. We are considering adding a non-null annotation to the language. This would most likely be by adding an annotation java.lang.NonNull. This would allow developers to annotate variables like this: @NonNull List<String> ss = new ArrayList<String>(); Also, the compiler should be changed to check the correctness of the annotations. ###@###.### 2005-04-15 18:50:18 GMT
15-04-2005