SlideShare a Scribd company logo
1 of 35
Download to read offline
8 
8 
JJDDTT eemmbbrraacceess TTyyppee AAnnnnoottaattiioonnss 
Stephan Herrmann 
GK Software 
Java 8 ready
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 2 
8 
Eclipse and Java™ 8 
● Java 8 features supported: 
– JSR308 - Type Annotations. 
– JEP120 - Repeating Annotations. 
– JEP118 - Method Parameter Reflection. 
– JSR269 - Pluggable Annotation Processor API & 
javax.lang.model API enhancements for Java 8. 
– JSR 335 – Lambda Expressions 
● Lambda expressions & method/constructor references 
● Support for “code carrying” interface methods 
● Enhanced target typing / new overload resolution & type 
inference
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 3 
8 
λ 
(JSR 335)
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 4 
8 
λ 
(JSR 335) Tomorrow 17:00 to 18:00: 
Grand Peninsula C 
JDT embraces lambda expressions 
● Srikanth [IBM India] 
● Noopur Gupta [IBM India] 
● Stephan Herrmann
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 5 
8 
@ 
(JSR 308)
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 6 
8 
Annotations in more Places 
● Java 5: annotate declarations 
– ElementType: packages, classes, fields, methods, locals … 
● Java 8: annotate types 
– ElementType.TYPE_USE 
– ElementType.TYPE_PARAMETER 
SSoo wwhhaatt??
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 7 
8 
Why Care About Types? 
● Dynamically typed languages 
– anything goes 
– but may fail at runtime 
– e.g.: “method not understood” 
● Type = Constraints on values 
To statically detect anomalies 
– missing capability 
– incompatible assignment 
– undeclared capability 
dog1 = new Dog(); 
dog1.bark(); 
dog2 = new Object(); 
dog2.bark();
Annotate source code: 
● make assumptions explicit 
● convince the compiler that code is safe 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 8 
8 
Why Care About Types? 
● Dynamically typed languages 
– anything goes 
– but may fail at runtime 
– e.g.: “method not understood” 
● Type = Constraints on values 
To statically detect anomalies 
– missing capability 
– incompatible assignment 
– undeclared capability 
dog1 = new Dog(); 
dog1.bark(); 
dog2 = new Object(); 
dog2.bark(); 
Annotate source code: 
● make assumptions explicit 
● convince the compiler that code is safe
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 9 
8 
Why Care About Types? 
● Constraint checking avoids errors 
– No Such Method / Field 
● Basic statically typed OO 
– ClassCastException 
● Generics 
– ??Exception 
● SWTException("Invalid thread access") 
● … 
● NullPointerException
Let the Type System 8 
Handle Nullity 
● Ideally: Java would force explicit choice 
– String definitely a String, never null 
– String? either a String or null 
– Type system ensures: no dereferencing of null 
● Nullity as a language feature? 
– Heavy weight, incompatible change 
– Language change for each new constraint? 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 10
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 11 
8 
Pluggable Type System 
● Make it easier to add new constraints 
– Only one new syntax for all kinds of constraints 
● Make it easier to add new type checkers 
– Checker Framework (Michael Ernst – U of Washington) 
● Examples 
– @NonNull 
– @Interned equals(== , equals) 
– @Immutable value cannot change (Java 5 ?) 
– @ReadOnly value cannot change via this reference 
– @UI code requires to run on the SWT UI thread
Can't Java 5 Do All This? 
@Target(ElementType.PARAMETER) 
@interface NonNull5 {} 
void java5(@NonNull5 String arg); 
arg is qualified to be non-null 
@Target(ElementType.TYPE_USE) 
@interface NonNull8 {} 
void java8(@NonNull8 String arg); 
String is qualified to be non-null 
@Target(ElementType.METHOD) 
@interface NonNull5 {} 
@NonNull5 String java5(); 
String is java5 is qualified to be non-null qualified to be non-null 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 12 
8 
@Target(ElementType.TYPE_USE) 
@interface NonNull8 {} 
@NonNull8 String java8(); 
● We've been lying about the method result 
– but we can't lie about everything, e.g.: 
void letemBark(@NonNull List<Dog> dogs) { 
dogs.get(0).bark(); 
} 
NPE?
l1 cannot contain 
null elements 
Null type mismatch: required '@NonNull String' 
but the provided value is null 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 13 
8 
void bad(List<String> unknown, List<@Nullable String> withNulls) { 
@NonNull List<@NonNull String> l1 = new ArrayList<>(); 
l1.add(null); 
String first = l1.get(0); 
if (first == null) return; 
l1 = unknown; 
l1 = withNulls; 
String canNull = withNulls.get(0); 
System.out.println(canNull.toUpperCase()); 
} 
@NonNull List<@Nullable String> l2 = new ArrayList<>(); 
l2 can contain 
null elements 
Annotated Generics 
void good() { 
@NonNull List<@NonNull String> l1 = new ArrayList<>(); 
l1.add("Hello"); 
for (String elem : l1) 
System.out.println(elem.toUpperCase()); 
l2.add(null); 
for (String unknown : l2) 
if (unknown != null) 
System.out.println(unknown.toUpperCase()); 
} 
Null type mismatch: required '@NonNull String' 
but the provided value is null
l1 cannot contain 
null elements 
Null comparison always yields false: 
The variable first cannot be null at this location 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 14 
8 
void bad(List<String> unknown, List<@Nullable String> withNulls) { 
@NonNull List<@NonNull String> l1 = new ArrayList<>(); 
l1.add(null); 
String first = l1.get(0); 
if (first == null) return; 
l1 = unknown; 
l1 = withNulls; 
String canNull = withNulls.get(0); 
System.out.println(canNull.toUpperCase()); 
} 
@NonNull List<@Nullable String> l2 = new ArrayList<>(); 
l2 can contain 
null elements 
Annotated Generics 
void good() { 
@NonNull List<@NonNull String> l1 = new ArrayList<>(); 
l1.add("Hello"); 
for (String elem : l1) 
System.out.println(elem.toUpperCase()); 
l2.add(null); 
for (String unknown : l2) 
if (unknown != null) 
System.out.println(unknown.toUpperCase()); 
} 
Null comparison always yields false: 
The variable first cannot be null at this location
l1 cannot contain 
null elements 
Null type safety (type annotations): The expression of type 'List<String>' 
needs unchecked conversion to conform to '@NonNull List<@NonNull String>' 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 15 
8 
void bad(List<String> unknown, List<@Nullable String> withNulls) { 
@NonNull List<@NonNull String> l1 = new ArrayList<>(); 
l1.add(null); 
String first = l1.get(0); 
if (first == null) return; 
l1 = unknown; 
l1 = withNulls; 
String canNull = withNulls.get(0); 
System.out.println(canNull.toUpperCase()); 
} 
@NonNull List<@Nullable String> l2 = new ArrayList<>(); 
l2 can contain 
null elements 
Annotated Generics 
void good() { 
@NonNull List<@NonNull String> l1 = new ArrayList<>(); 
l1.add("Hello"); 
for (String elem : l1) 
System.out.println(elem.toUpperCase()); 
l2.add(null); 
for (String unknown : l2) 
if (unknown != null) 
System.out.println(unknown.toUpperCase()); 
} 
Null type safety (type annotations): The expression of type 'List<String>' 
needs unchecked conversion to conform to '@NonNull List<@NonNull String>'
l1 cannot contain 
null elements 
Null type mismatch (type annotations): 
required '@NonNull List<@NonNull String>' 
but this expression has type 'List<@Nullable String>' 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 16 
8 
void bad(List<String> unknown, List<@Nullable String> withNulls) { 
@NonNull List<@NonNull String> l1 = new ArrayList<>(); 
l1.add(null); 
String first = l1.get(0); 
if (first == null) return; 
l1 = unknown; 
l1 = withNulls; 
String canNull = withNulls.get(0); 
System.out.println(canNull.toUpperCase()); 
} 
@NonNull List<@Nullable String> l2 = new ArrayList<>(); 
l2 can contain 
null elements 
Annotated Generics 
void good() { 
@NonNull List<@NonNull String> l1 = new ArrayList<>(); 
l1.add("Hello"); 
for (String elem : l1) 
System.out.println(elem.toUpperCase()); 
l2.add(null); 
for (String unknown : l2) 
if (unknown != null) 
System.out.println(unknown.toUpperCase()); 
} 
Null type mismatch (type annotations): 
required '@NonNull List<@NonNull String>' 
but this expression has type 'List<@Nullable String>'
l1 cannot contain 
null elements 
Potential null pointer access: 
The variable canNull may be null at this location 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 17 
8 
void bad(List<String> unknown, List<@Nullable String> withNulls) { 
@NonNull List<@NonNull String> l1 = new ArrayList<>(); 
l1.add(null); 
String first = l1.get(0); 
if (first == null) return; 
l1 = unknown; 
l1 = withNulls; 
String canNull = withNulls.get(0); 
System.out.println(canNull.toUpperCase()); 
} 
@NonNull List<@Nullable String> l2 = new ArrayList<>(); 
l2 can contain 
null elements 
Annotated Generics 
void good() { 
@NonNull List<@NonNull String> l1 = new ArrayList<>(); 
l1.add("Hello"); 
for (String elem : l1) 
System.out.println(elem.toUpperCase()); 
l2.add(null); 
for (String unknown : l2) 
if (unknown != null) 
System.out.println(unknown.toUpperCase()); 
} 
Potential null pointer access: 
The variable canNull may be null at this location
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 18 
8 
Theorie for API design 
● Terminologie 
– Type parameter, type variable, type argument, type bound 
– Covariance, contravariance, invariance 
● Choosing the right level of genericity 
– Always @NonNull, always @Nullable? 
● easier for the library developer 
– Should clients be able to choose? 
● more widely usable
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 19 
8 
Generic API 
● The classic declaration 
– Unconstrained type parameter: 
● public interface List<T> { … } 
● Client side 
– Free to choose the type argument: 
● List<@NonNull Person> 
● List<@Nullable Person> 
● Implementer 
– No knowledge about type variable T 
– Must assume the worst 
● need to check on dereference 
● cannot assign null to a T variable 
Caveat: 
Strict checking 
not yet implemented
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 20 
8 
Type Bounds 
● Implementer needs more knowledge 
– constrain the type 
● class X <T extends Comparable> { … } 
– constrain the nullness 
● class X <T extends @NonNull Object> { … } 
– client can provide same or more specific type 
● @NonNull Object <: @Nullable Object
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 21 
8 
API Methods 
● What's the contract? 
– abstract O apply (@Nullable I arg); 
● Callers 
– can pass null 
● All implementers 
– must accept null 
– cannot override @Nullable → @NonNull 
– could override @NonNull → @Nullable 
● contravariant parameters 
● covariant return
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 22 
8 
What does it cost? 
● How many additional annotations? 
– will code become unreadable due to null annotations? 
● We have 2 strong mechanisms to alleviate the burden 
DDeemmoo TTiimmee
void test (@NonNull String [] stringsOrNulls) { 
System.out.println(stringsOrNulls[0]); 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 23 
8 
Caveat: Arrays 
● Semantics are changing from Java 7 to Java 8 
} 
array of nonnull elements the array can still be null Þ NPE 
void test (String @NonNull [] stringsOrNulls) { 
System.out.println(stringsOrNulls[0]); 
} 
nonnull array NPE- safe (but may print “null”)
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 24 
8 
More Type Annotations
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 25 
8 
JavaUI 
● Research by Colin Gordon et al 
– Statically check that 
● code needing access to the SWT display is called from the UI thread 
– Is the approach safe?
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 26 
8 
JavaUI 
● Research by Colin Gordon et al 
– Can we statically check that 
● code needing access to the SWT display is called from the UI thread 
– Is the approach safe?
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 27 
8 
JavaUI 
● Research by Colin Gordon et al 
– To statically check that 
● code needing access to the SWT display is called from the UI thread 
– Is the approach safe? 
– Is it practical?
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 28 
8 
JavaUI 
● Research by Colin Gordon et al 
– To statically check that 
● code needing access to the SWT display is called from the UI thread 
– Is the approach safe? 
– Is it practical?
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 29 
8 
JavaUI 
● Research by Colin Gordon et al 
– To statically check that 
● code needing access to the SWT display is called from the UI thread 
– Is the approach safe? 
– Is it practical? 
● Evaluated against 8 programs / plugins – 90,000+ UI LOC 
● Found 8 real defects 
● Extensive assessment of study results 
– Does it need JSR 308? 
● For full expressiveness: yes 
● But much can already be done with SE5 annotations
aka “Symbol” 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 30 
8 
TypeBinding Backstage Story 
● Type bindings are “interned” 
– OK to use == 
● Broken by encoding type annotations in type bindings 
● Solution 
– Find/replace == comparisons for T <: TypeBinding 
– Tweak our compiler report affected locations 
– Plan: publish the tweak, controlled by @Uninterned
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 31 
8 
Status 
● Null Annotations 
– org.eclipse.jdt.annotation_2.0.0 
● @NonNull, @Nullable specify Target(TYPE_USE) 
● @NonNullByDefault: more fine tuning 
● Null Analysis (per compiler option) 
– Nullness is an integral part of the type system 
– Fine tuned defaults only in Luna 
– TODO: Strict checking against type variables
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 32 
8 
Status 
● Null Annotations 
● Null Analysis (per compiler option) 
● Planned: @Uninterned 
– Detect accidental comparison using == or != 
● Proposed: @UiEffect, @Ui … 
– by [Colin S. Gordon, Werner Dietl, Michael D. Ernst, and Dan 
Grossman] 
– SWT: bye, bye, “Invalid thread access”
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 33 
8 
Status 
● Null Annotations 
● Null Analysis (per compiler option) 
● Planned: @Uninterned 
● Proposed: @UiEffect, @Ui … 
● JDT/UI 
– OK: completion, refactoring, etc. 
– TODO: show in hover 
– TODO: update / add more quickfixes
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 34 
8 
Status 
● Null Annotations 
● Null Analysis (per compiler option) 
● Planned: @Uninterned 
● Proposed: @UiEffect, @Ui … 
● JDT/UI 
DDoo YYoouu ccaarree aabboouutt TTyyppeess??
Dramatis personæ 
Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 35 
8 
Java 8 ready 
● Jay Arthanareeswaran 
● Anirban Chakarborty 
● Manoj Palat 
● Shankha Banerjee 
● Manju Mathew 
● Noopur Gupta 
● Deepak Azad 
● Srikanth Sankaran 
● Olivier Thomann 
● Andy Clement 
● Michael Rennie 
● Jesper S. Møller 
● Walter Harley 
● Stephan Herrmann 
● Dani Megert 
● Markus Keller 
● Release: TODAY!! 
http://download.eclipse.org/eclipse/downloads

More Related Content

What's hot

Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in JavaErhan Bagdemir
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project LambdaRahman USTA
 
Programming picaresque
Programming picaresqueProgramming picaresque
Programming picaresqueBret McGuire
 
Beyond design patterns phpnw14
Beyond design patterns   phpnw14Beyond design patterns   phpnw14
Beyond design patterns phpnw14Anthony Ferrara
 
Don't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo EditionDon't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo EditionAnthony Ferrara
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming LangugeYaser Jaradeh
 
Don't be STUPID, Grasp SOLID - North East PHP
Don't be STUPID, Grasp SOLID - North East PHPDon't be STUPID, Grasp SOLID - North East PHP
Don't be STUPID, Grasp SOLID - North East PHPAnthony Ferrara
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scalaStratio
 
DIY: Analyse statique en Java
DIY: Analyse statique en JavaDIY: Analyse statique en Java
DIY: Analyse statique en Javalyonjug
 
Gentle Introduction To Lisp
Gentle Introduction To LispGentle Introduction To Lisp
Gentle Introduction To LispDamien Garaud
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features OverviewSergii Stets
 

What's hot (20)

Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 
Programming picaresque
Programming picaresqueProgramming picaresque
Programming picaresque
 
Ch6
Ch6Ch6
Ch6
 
Types of Parser
Types of ParserTypes of Parser
Types of Parser
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Beyond design patterns phpnw14
Beyond design patterns   phpnw14Beyond design patterns   phpnw14
Beyond design patterns phpnw14
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Don't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo EditionDon't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo Edition
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
 
Don't be STUPID, Grasp SOLID - North East PHP
Don't be STUPID, Grasp SOLID - North East PHPDon't be STUPID, Grasp SOLID - North East PHP
Don't be STUPID, Grasp SOLID - North East PHP
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
 
Python basics
Python basicsPython basics
Python basics
 
DIY: Analyse statique en Java
DIY: Analyse statique en JavaDIY: Analyse statique en Java
DIY: Analyse statique en Java
 
Gentle Introduction To Lisp
Gentle Introduction To LispGentle Introduction To Lisp
Gentle Introduction To Lisp
 
Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 

Similar to Annotation based null analysis in Eclipse JDT

Introduction to Erlang Programming Language
Introduction to Erlang Programming LanguageIntroduction to Erlang Programming Language
Introduction to Erlang Programming LanguageYasas Gunarathne
 
Flow or Type - how to React to that?
Flow or Type - how to React to that?Flow or Type - how to React to that?
Flow or Type - how to React to that?Krešimir Antolić
 
Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)Peter Antman
 
Basics of Python Programming in one PDF File.pdf
Basics of Python Programming in one PDF File.pdfBasics of Python Programming in one PDF File.pdf
Basics of Python Programming in one PDF File.pdfKrizanReyFamindalan
 
What’s new in Gradualizer? Gradually typing Erlang and Elixir | Lambda Days 2022
What’s new in Gradualizer? Gradually typing Erlang and Elixir | Lambda Days 2022What’s new in Gradualizer? Gradually typing Erlang and Elixir | Lambda Days 2022
What’s new in Gradualizer? Gradually typing Erlang and Elixir | Lambda Days 2022RadekSzymczyszyn
 
Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Codemotion
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To ScalaBasuk
 
DEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World HaskellDEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World HaskellBryan O'Sullivan
 
Amber and beyond: Java language changes
Amber and beyond: Java language changesAmber and beyond: Java language changes
Amber and beyond: Java language changesStephen Colebourne
 
Python Workshop. LUG Maniapl
Python Workshop. LUG ManiaplPython Workshop. LUG Maniapl
Python Workshop. LUG ManiaplAnkur Shrivastava
 
Erlang kickstart
Erlang kickstartErlang kickstart
Erlang kickstartRyan Brown
 
Introduction to Erlang Part 1
Introduction to Erlang Part 1Introduction to Erlang Part 1
Introduction to Erlang Part 1Dmitry Zinoviev
 

Similar to Annotation based null analysis in Eclipse JDT (20)

Introduction to Erlang Programming Language
Introduction to Erlang Programming LanguageIntroduction to Erlang Programming Language
Introduction to Erlang Programming Language
 
Cs3430 lecture 15
Cs3430 lecture 15Cs3430 lecture 15
Cs3430 lecture 15
 
Flow or Type - how to React to that?
Flow or Type - how to React to that?Flow or Type - how to React to that?
Flow or Type - how to React to that?
 
Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)
 
Basics of Python Programming in one PDF File.pdf
Basics of Python Programming in one PDF File.pdfBasics of Python Programming in one PDF File.pdf
Basics of Python Programming in one PDF File.pdf
 
What’s new in Gradualizer? Gradually typing Erlang and Elixir | Lambda Days 2022
What’s new in Gradualizer? Gradually typing Erlang and Elixir | Lambda Days 2022What’s new in Gradualizer? Gradually typing Erlang and Elixir | Lambda Days 2022
What’s new in Gradualizer? Gradually typing Erlang and Elixir | Lambda Days 2022
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
 
Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018
 
Lazy java
Lazy javaLazy java
Lazy java
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 
Perl Basics with Examples
Perl Basics with ExamplesPerl Basics with Examples
Perl Basics with Examples
 
python and perl
python and perlpython and perl
python and perl
 
DEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World HaskellDEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World Haskell
 
COMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax AnalysisCOMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax Analysis
 
Amber and beyond: Java language changes
Amber and beyond: Java language changesAmber and beyond: Java language changes
Amber and beyond: Java language changes
 
Python Workshop. LUG Maniapl
Python Workshop. LUG ManiaplPython Workshop. LUG Maniapl
Python Workshop. LUG Maniapl
 
Erlang kickstart
Erlang kickstartErlang kickstart
Erlang kickstart
 
Introduction to Erlang Part 1
Introduction to Erlang Part 1Introduction to Erlang Part 1
Introduction to Erlang Part 1
 
Perl-Tutorial
Perl-TutorialPerl-Tutorial
Perl-Tutorial
 

More from Eclipse Day India

Java Performance Testing for Everyone - Shelley Lambert
Java Performance Testing for Everyone - Shelley LambertJava Performance Testing for Everyone - Shelley Lambert
Java Performance Testing for Everyone - Shelley LambertEclipse Day India
 
Eclipse IDE Tips and Tricks - Lakshmi Priya Shanmugam
Eclipse IDE Tips and Tricks - Lakshmi Priya ShanmugamEclipse IDE Tips and Tricks - Lakshmi Priya Shanmugam
Eclipse IDE Tips and Tricks - Lakshmi Priya ShanmugamEclipse Day India
 
Pattern Matching in Java - Srikanth Sankaran
Pattern Matching in Java - Srikanth SankaranPattern Matching in Java - Srikanth Sankaran
Pattern Matching in Java - Srikanth SankaranEclipse Day India
 
Machine Learning for Java Developers - Nasser Ebrahim
Machine Learning for Java Developers - Nasser EbrahimMachine Learning for Java Developers - Nasser Ebrahim
Machine Learning for Java Developers - Nasser EbrahimEclipse Day India
 
Scaling Eclipse on HiDPI Monitors - Niraj Modi
Scaling Eclipse on HiDPI Monitors - Niraj ModiScaling Eclipse on HiDPI Monitors - Niraj Modi
Scaling Eclipse on HiDPI Monitors - Niraj ModiEclipse Day India
 
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...Eclipse Day India
 
Supporting Java™ 9 in Eclipse - A critical perspective - Stephan Herrmann
Supporting Java™ 9 in Eclipse - A critical perspective - Stephan HerrmannSupporting Java™ 9 in Eclipse - A critical perspective - Stephan Herrmann
Supporting Java™ 9 in Eclipse - A critical perspective - Stephan HerrmannEclipse Day India
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India
 
Eclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JITEclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JITEclipse Day India
 
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India
 
Eclipse Day India 2015 - Java 9
Eclipse Day India 2015 - Java 9Eclipse Day India 2015 - Java 9
Eclipse Day India 2015 - Java 9Eclipse Day India
 
Eclipse Day India 2015 - Keynote - Stephan Herrmann
Eclipse Day India 2015 - Keynote - Stephan HerrmannEclipse Day India 2015 - Keynote - Stephan Herrmann
Eclipse Day India 2015 - Keynote - Stephan HerrmannEclipse Day India
 
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automation
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automationEclipse Day India 2015 - Eclipse RCP testing using Jubula based automation
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automationEclipse Day India
 
Eclipse Day India 2015 - Oomph
Eclipse Day India 2015 - OomphEclipse Day India 2015 - Oomph
Eclipse Day India 2015 - OomphEclipse Day India
 
Eclipse Day India 2015 - Keynote (Mike Milinkovich)
Eclipse Day India 2015 - Keynote (Mike Milinkovich)Eclipse Day India 2015 - Keynote (Mike Milinkovich)
Eclipse Day India 2015 - Keynote (Mike Milinkovich)Eclipse Day India
 
Eclipse Day India 2015 - Unleashing the Java 8 Tooling in Eclipse
Eclipse Day India 2015 - Unleashing the Java 8 Tooling in EclipseEclipse Day India 2015 - Unleashing the Java 8 Tooling in Eclipse
Eclipse Day India 2015 - Unleashing the Java 8 Tooling in EclipseEclipse Day India
 

More from Eclipse Day India (20)

Java Performance Testing for Everyone - Shelley Lambert
Java Performance Testing for Everyone - Shelley LambertJava Performance Testing for Everyone - Shelley Lambert
Java Performance Testing for Everyone - Shelley Lambert
 
Eclipse IDE Tips and Tricks - Lakshmi Priya Shanmugam
Eclipse IDE Tips and Tricks - Lakshmi Priya ShanmugamEclipse IDE Tips and Tricks - Lakshmi Priya Shanmugam
Eclipse IDE Tips and Tricks - Lakshmi Priya Shanmugam
 
Pattern Matching in Java - Srikanth Sankaran
Pattern Matching in Java - Srikanth SankaranPattern Matching in Java - Srikanth Sankaran
Pattern Matching in Java - Srikanth Sankaran
 
Machine Learning for Java Developers - Nasser Ebrahim
Machine Learning for Java Developers - Nasser EbrahimMachine Learning for Java Developers - Nasser Ebrahim
Machine Learning for Java Developers - Nasser Ebrahim
 
Scaling Eclipse on HiDPI Monitors - Niraj Modi
Scaling Eclipse on HiDPI Monitors - Niraj ModiScaling Eclipse on HiDPI Monitors - Niraj Modi
Scaling Eclipse on HiDPI Monitors - Niraj Modi
 
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
 
Supporting Java™ 9 in Eclipse - A critical perspective - Stephan Herrmann
Supporting Java™ 9 in Eclipse - A critical perspective - Stephan HerrmannSupporting Java™ 9 in Eclipse - A critical perspective - Stephan Herrmann
Supporting Java™ 9 in Eclipse - A critical perspective - Stephan Herrmann
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
 
Eclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JITEclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JIT
 
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 Overview
 
Eclipse Day India 2015 - Java 9
Eclipse Day India 2015 - Java 9Eclipse Day India 2015 - Java 9
Eclipse Day India 2015 - Java 9
 
Eclipse Day India 2015 - Keynote - Stephan Herrmann
Eclipse Day India 2015 - Keynote - Stephan HerrmannEclipse Day India 2015 - Keynote - Stephan Herrmann
Eclipse Day India 2015 - Keynote - Stephan Herrmann
 
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automation
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automationEclipse Day India 2015 - Eclipse RCP testing using Jubula based automation
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automation
 
Eclipse Day India 2015 - Oomph
Eclipse Day India 2015 - OomphEclipse Day India 2015 - Oomph
Eclipse Day India 2015 - Oomph
 
Eclipse Day India 2015 - Keynote (Mike Milinkovich)
Eclipse Day India 2015 - Keynote (Mike Milinkovich)Eclipse Day India 2015 - Keynote (Mike Milinkovich)
Eclipse Day India 2015 - Keynote (Mike Milinkovich)
 
Eclipse Day India 2015 - Unleashing the Java 8 Tooling in Eclipse
Eclipse Day India 2015 - Unleashing the Java 8 Tooling in EclipseEclipse Day India 2015 - Unleashing the Java 8 Tooling in Eclipse
Eclipse Day India 2015 - Unleashing the Java 8 Tooling in Eclipse
 
IDS and Bluemix
IDS and BluemixIDS and Bluemix
IDS and Bluemix
 
SWT - Technical Deep Dive
SWT - Technical Deep DiveSWT - Technical Deep Dive
SWT - Technical Deep Dive
 
PDE builds or Maven
PDE builds or MavenPDE builds or Maven
PDE builds or Maven
 
Orion - IDE on the cloud
Orion - IDE on the cloudOrion - IDE on the cloud
Orion - IDE on the cloud
 

Recently uploaded

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Annotation based null analysis in Eclipse JDT

  • 1. 8 8 JJDDTT eemmbbrraacceess TTyyppee AAnnnnoottaattiioonnss Stephan Herrmann GK Software Java 8 ready
  • 2. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 2 8 Eclipse and Java™ 8 ● Java 8 features supported: – JSR308 - Type Annotations. – JEP120 - Repeating Annotations. – JEP118 - Method Parameter Reflection. – JSR269 - Pluggable Annotation Processor API & javax.lang.model API enhancements for Java 8. – JSR 335 – Lambda Expressions ● Lambda expressions & method/constructor references ● Support for “code carrying” interface methods ● Enhanced target typing / new overload resolution & type inference
  • 3. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 3 8 λ (JSR 335)
  • 4. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 4 8 λ (JSR 335) Tomorrow 17:00 to 18:00: Grand Peninsula C JDT embraces lambda expressions ● Srikanth [IBM India] ● Noopur Gupta [IBM India] ● Stephan Herrmann
  • 5. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 5 8 @ (JSR 308)
  • 6. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 6 8 Annotations in more Places ● Java 5: annotate declarations – ElementType: packages, classes, fields, methods, locals … ● Java 8: annotate types – ElementType.TYPE_USE – ElementType.TYPE_PARAMETER SSoo wwhhaatt??
  • 7. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 7 8 Why Care About Types? ● Dynamically typed languages – anything goes – but may fail at runtime – e.g.: “method not understood” ● Type = Constraints on values To statically detect anomalies – missing capability – incompatible assignment – undeclared capability dog1 = new Dog(); dog1.bark(); dog2 = new Object(); dog2.bark();
  • 8. Annotate source code: ● make assumptions explicit ● convince the compiler that code is safe Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 8 8 Why Care About Types? ● Dynamically typed languages – anything goes – but may fail at runtime – e.g.: “method not understood” ● Type = Constraints on values To statically detect anomalies – missing capability – incompatible assignment – undeclared capability dog1 = new Dog(); dog1.bark(); dog2 = new Object(); dog2.bark(); Annotate source code: ● make assumptions explicit ● convince the compiler that code is safe
  • 9. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 9 8 Why Care About Types? ● Constraint checking avoids errors – No Such Method / Field ● Basic statically typed OO – ClassCastException ● Generics – ??Exception ● SWTException("Invalid thread access") ● … ● NullPointerException
  • 10. Let the Type System 8 Handle Nullity ● Ideally: Java would force explicit choice – String definitely a String, never null – String? either a String or null – Type system ensures: no dereferencing of null ● Nullity as a language feature? – Heavy weight, incompatible change – Language change for each new constraint? Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 10
  • 11. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 11 8 Pluggable Type System ● Make it easier to add new constraints – Only one new syntax for all kinds of constraints ● Make it easier to add new type checkers – Checker Framework (Michael Ernst – U of Washington) ● Examples – @NonNull – @Interned equals(== , equals) – @Immutable value cannot change (Java 5 ?) – @ReadOnly value cannot change via this reference – @UI code requires to run on the SWT UI thread
  • 12. Can't Java 5 Do All This? @Target(ElementType.PARAMETER) @interface NonNull5 {} void java5(@NonNull5 String arg); arg is qualified to be non-null @Target(ElementType.TYPE_USE) @interface NonNull8 {} void java8(@NonNull8 String arg); String is qualified to be non-null @Target(ElementType.METHOD) @interface NonNull5 {} @NonNull5 String java5(); String is java5 is qualified to be non-null qualified to be non-null Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 12 8 @Target(ElementType.TYPE_USE) @interface NonNull8 {} @NonNull8 String java8(); ● We've been lying about the method result – but we can't lie about everything, e.g.: void letemBark(@NonNull List<Dog> dogs) { dogs.get(0).bark(); } NPE?
  • 13. l1 cannot contain null elements Null type mismatch: required '@NonNull String' but the provided value is null Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 13 8 void bad(List<String> unknown, List<@Nullable String> withNulls) { @NonNull List<@NonNull String> l1 = new ArrayList<>(); l1.add(null); String first = l1.get(0); if (first == null) return; l1 = unknown; l1 = withNulls; String canNull = withNulls.get(0); System.out.println(canNull.toUpperCase()); } @NonNull List<@Nullable String> l2 = new ArrayList<>(); l2 can contain null elements Annotated Generics void good() { @NonNull List<@NonNull String> l1 = new ArrayList<>(); l1.add("Hello"); for (String elem : l1) System.out.println(elem.toUpperCase()); l2.add(null); for (String unknown : l2) if (unknown != null) System.out.println(unknown.toUpperCase()); } Null type mismatch: required '@NonNull String' but the provided value is null
  • 14. l1 cannot contain null elements Null comparison always yields false: The variable first cannot be null at this location Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 14 8 void bad(List<String> unknown, List<@Nullable String> withNulls) { @NonNull List<@NonNull String> l1 = new ArrayList<>(); l1.add(null); String first = l1.get(0); if (first == null) return; l1 = unknown; l1 = withNulls; String canNull = withNulls.get(0); System.out.println(canNull.toUpperCase()); } @NonNull List<@Nullable String> l2 = new ArrayList<>(); l2 can contain null elements Annotated Generics void good() { @NonNull List<@NonNull String> l1 = new ArrayList<>(); l1.add("Hello"); for (String elem : l1) System.out.println(elem.toUpperCase()); l2.add(null); for (String unknown : l2) if (unknown != null) System.out.println(unknown.toUpperCase()); } Null comparison always yields false: The variable first cannot be null at this location
  • 15. l1 cannot contain null elements Null type safety (type annotations): The expression of type 'List<String>' needs unchecked conversion to conform to '@NonNull List<@NonNull String>' Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 15 8 void bad(List<String> unknown, List<@Nullable String> withNulls) { @NonNull List<@NonNull String> l1 = new ArrayList<>(); l1.add(null); String first = l1.get(0); if (first == null) return; l1 = unknown; l1 = withNulls; String canNull = withNulls.get(0); System.out.println(canNull.toUpperCase()); } @NonNull List<@Nullable String> l2 = new ArrayList<>(); l2 can contain null elements Annotated Generics void good() { @NonNull List<@NonNull String> l1 = new ArrayList<>(); l1.add("Hello"); for (String elem : l1) System.out.println(elem.toUpperCase()); l2.add(null); for (String unknown : l2) if (unknown != null) System.out.println(unknown.toUpperCase()); } Null type safety (type annotations): The expression of type 'List<String>' needs unchecked conversion to conform to '@NonNull List<@NonNull String>'
  • 16. l1 cannot contain null elements Null type mismatch (type annotations): required '@NonNull List<@NonNull String>' but this expression has type 'List<@Nullable String>' Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 16 8 void bad(List<String> unknown, List<@Nullable String> withNulls) { @NonNull List<@NonNull String> l1 = new ArrayList<>(); l1.add(null); String first = l1.get(0); if (first == null) return; l1 = unknown; l1 = withNulls; String canNull = withNulls.get(0); System.out.println(canNull.toUpperCase()); } @NonNull List<@Nullable String> l2 = new ArrayList<>(); l2 can contain null elements Annotated Generics void good() { @NonNull List<@NonNull String> l1 = new ArrayList<>(); l1.add("Hello"); for (String elem : l1) System.out.println(elem.toUpperCase()); l2.add(null); for (String unknown : l2) if (unknown != null) System.out.println(unknown.toUpperCase()); } Null type mismatch (type annotations): required '@NonNull List<@NonNull String>' but this expression has type 'List<@Nullable String>'
  • 17. l1 cannot contain null elements Potential null pointer access: The variable canNull may be null at this location Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 17 8 void bad(List<String> unknown, List<@Nullable String> withNulls) { @NonNull List<@NonNull String> l1 = new ArrayList<>(); l1.add(null); String first = l1.get(0); if (first == null) return; l1 = unknown; l1 = withNulls; String canNull = withNulls.get(0); System.out.println(canNull.toUpperCase()); } @NonNull List<@Nullable String> l2 = new ArrayList<>(); l2 can contain null elements Annotated Generics void good() { @NonNull List<@NonNull String> l1 = new ArrayList<>(); l1.add("Hello"); for (String elem : l1) System.out.println(elem.toUpperCase()); l2.add(null); for (String unknown : l2) if (unknown != null) System.out.println(unknown.toUpperCase()); } Potential null pointer access: The variable canNull may be null at this location
  • 18. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 18 8 Theorie for API design ● Terminologie – Type parameter, type variable, type argument, type bound – Covariance, contravariance, invariance ● Choosing the right level of genericity – Always @NonNull, always @Nullable? ● easier for the library developer – Should clients be able to choose? ● more widely usable
  • 19. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 19 8 Generic API ● The classic declaration – Unconstrained type parameter: ● public interface List<T> { … } ● Client side – Free to choose the type argument: ● List<@NonNull Person> ● List<@Nullable Person> ● Implementer – No knowledge about type variable T – Must assume the worst ● need to check on dereference ● cannot assign null to a T variable Caveat: Strict checking not yet implemented
  • 20. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 20 8 Type Bounds ● Implementer needs more knowledge – constrain the type ● class X <T extends Comparable> { … } – constrain the nullness ● class X <T extends @NonNull Object> { … } – client can provide same or more specific type ● @NonNull Object <: @Nullable Object
  • 21. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 21 8 API Methods ● What's the contract? – abstract O apply (@Nullable I arg); ● Callers – can pass null ● All implementers – must accept null – cannot override @Nullable → @NonNull – could override @NonNull → @Nullable ● contravariant parameters ● covariant return
  • 22. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 22 8 What does it cost? ● How many additional annotations? – will code become unreadable due to null annotations? ● We have 2 strong mechanisms to alleviate the burden DDeemmoo TTiimmee
  • 23. void test (@NonNull String [] stringsOrNulls) { System.out.println(stringsOrNulls[0]); Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 23 8 Caveat: Arrays ● Semantics are changing from Java 7 to Java 8 } array of nonnull elements the array can still be null Þ NPE void test (String @NonNull [] stringsOrNulls) { System.out.println(stringsOrNulls[0]); } nonnull array NPE- safe (but may print “null”)
  • 24. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 24 8 More Type Annotations
  • 25. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 25 8 JavaUI ● Research by Colin Gordon et al – Statically check that ● code needing access to the SWT display is called from the UI thread – Is the approach safe?
  • 26. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 26 8 JavaUI ● Research by Colin Gordon et al – Can we statically check that ● code needing access to the SWT display is called from the UI thread – Is the approach safe?
  • 27. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 27 8 JavaUI ● Research by Colin Gordon et al – To statically check that ● code needing access to the SWT display is called from the UI thread – Is the approach safe? – Is it practical?
  • 28. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 28 8 JavaUI ● Research by Colin Gordon et al – To statically check that ● code needing access to the SWT display is called from the UI thread – Is the approach safe? – Is it practical?
  • 29. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 29 8 JavaUI ● Research by Colin Gordon et al – To statically check that ● code needing access to the SWT display is called from the UI thread – Is the approach safe? – Is it practical? ● Evaluated against 8 programs / plugins – 90,000+ UI LOC ● Found 8 real defects ● Extensive assessment of study results – Does it need JSR 308? ● For full expressiveness: yes ● But much can already be done with SE5 annotations
  • 30. aka “Symbol” Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 30 8 TypeBinding Backstage Story ● Type bindings are “interned” – OK to use == ● Broken by encoding type annotations in type bindings ● Solution – Find/replace == comparisons for T <: TypeBinding – Tweak our compiler report affected locations – Plan: publish the tweak, controlled by @Uninterned
  • 31. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 31 8 Status ● Null Annotations – org.eclipse.jdt.annotation_2.0.0 ● @NonNull, @Nullable specify Target(TYPE_USE) ● @NonNullByDefault: more fine tuning ● Null Analysis (per compiler option) – Nullness is an integral part of the type system – Fine tuned defaults only in Luna – TODO: Strict checking against type variables
  • 32. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 32 8 Status ● Null Annotations ● Null Analysis (per compiler option) ● Planned: @Uninterned – Detect accidental comparison using == or != ● Proposed: @UiEffect, @Ui … – by [Colin S. Gordon, Werner Dietl, Michael D. Ernst, and Dan Grossman] – SWT: bye, bye, “Invalid thread access”
  • 33. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 33 8 Status ● Null Annotations ● Null Analysis (per compiler option) ● Planned: @Uninterned ● Proposed: @UiEffect, @Ui … ● JDT/UI – OK: completion, refactoring, etc. – TODO: show in hover – TODO: update / add more quickfixes
  • 34. Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 34 8 Status ● Null Annotations ● Null Analysis (per compiler option) ● Planned: @Uninterned ● Proposed: @UiEffect, @Ui … ● JDT/UI DDoo YYoouu ccaarree aabboouutt TTyyppeess??
  • 35. Dramatis personæ Stephan Herrmann: JDT Embraces Type Annotations - EclipseCon North America 2014 # 35 8 Java 8 ready ● Jay Arthanareeswaran ● Anirban Chakarborty ● Manoj Palat ● Shankha Banerjee ● Manju Mathew ● Noopur Gupta ● Deepak Azad ● Srikanth Sankaran ● Olivier Thomann ● Andy Clement ● Michael Rennie ● Jesper S. Møller ● Walter Harley ● Stephan Herrmann ● Dani Megert ● Markus Keller ● Release: TODAY!! http://download.eclipse.org/eclipse/downloads