pluggable-types-demo-slides

pluggable-types-demo-slides - print(@Readonly Objectx)cfw_...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Preventing bugs with pluggable type checking Michael Ernst University of Washington Joint work with Mahmood Ali and Matthew Papi print( @Readonly Object x) { List< @NonNull String> lst; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Motivation java.lang.NullPointerException
Background image of page 2
Java’s type checking is too weak Type checking prevents many bugs int i = “hello”; // type error Type checking doesn’t prevent enough bugs System.console().readLine(); NullPointerException Collections.emptyList().add(“One”); UnsupportedOperationException
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Some errors are silent Date date = new Date(0); myMap.put(date, “Java Epoch”); date.setYear(70); myMap.put(date, “Linux Epoch”); Corrupted map dbStatement.executeQuery(userInput); UnsupportedOperationException Equality tests, initialization, data formatting, …
Background image of page 4
Solution: Pluggable type systems Design a type system to solve a specific problem Write type qualifiers in your code (or, type inference) @Immutable Date date = new Date(0); date.setTime(70); // compile-time error Type checker warns about violations (bugs) % javac -processor NullnessChecker MyFile.java MyFile.java:149: dereference of possibly-null reference bb2 allVars = bb2.vars; ^
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline Type qualifiers Pluggable type checkers Writing your own checker Conclusion
Background image of page 6
Type qualifiers Java 7 annotation syntax @Untainted String query; List< @NonNull String> strings; myGraph = ( @Immutable Graph) tmpGraph; class UnmodifiableList<T> implements @Readonly List< @Readonly T> {} Backward compatible : compile with any Java compiler List< /*@NonNull*/ String> strings;
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Benefits of type qualifiers Improve documentation Find bugs in programs Guarantee the absence of errors Aid compilers and analysis tools Reduce the need for assertions and run time checks
Background image of page 8
Outline Type qualifiers Pluggable type checkers Writing your own checker Conclusion
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/24/2012 for the course CSE 503 taught by Professor Davidnotikin during the Spring '11 term at University of Washington.

Page1 / 30

pluggable-types-demo-slides - print(@Readonly Objectx)cfw_...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online