SlideShare a Scribd company logo
1 of 36
Download to read offline
Fire in the type hole
Why you shouldn’t trust a Java compiler in everything
Heejong Lee (@heejongl)
– Mr. Unknown Java Compiler
“Do you trust me?”
Computer
Science
[Tool]
The Study of
Programming Languages
[Method]
The Study of Algorithm
• Reliable safety net for programming systems
• Statically verifying that something wrong will not
happen in the runtime
• Blazingly fast
A great step forward to the better world :
Type System
Type Systems
Type System
Safe programs Unsafe programs
Typed programs
• Verified by a type system implies a program will
never violate the rule that the type system
defines
• Failed by a type system does not implies a
program will violate the rule that the type system
defines
• Possibly, there exists a program which is safe
but a type system cannot verify its safety
Type System
Type System
1
Type System
1:int
Type System
1:int + “hello”
Type System
1:int + “hello”:string
Type System
1:int + “hello”:string
May cause segmentation fault, exception,
unexpected behavior in some languages
Type System
(1:int + “hello”:string):string
In Java, 1 will be automatically converted to string
Type System
(1:int + “hello”:string):int
Or, error: incompatible types: String cannot be
converted to int
Type System
String foo(int x) {
int y = 10 + x;
return y.toString();
}
void bar() {
foo(10);
}
foo : int -> string
= +
toString
bar : unit -> unit
foo( )
“…Really?”
One value to rule types all
• The most catastrophic design decision ever
made
• Tony Hoare introduced Null references in ALGOL
W back in 1965 “simply because it was so easy
to implement”
• Can be an any type, ultimately unarm the Java
type system
Null
foo : string -> string
bar : unit -> unit
foo( )
Type System
String foo(String x) {
return x.toUpperCase();
}
void bar() {
String s = null;
foo(s);
}
toUpperCase
foo : string -> string
bar : unit -> unit
foo( )
Type System
String foo(String x) {
return x.toUpperCase();
}
void bar() {
String s = null;
foo(s);
}
toUpperCase
• Impossible in general
• However, recent programming languages
introduce a typed null : Option[T] in Scala,
Optional<T> in Java8
How could we survive Null attacks
Null Checking Idioms
String x = getString();
String y = null;
if(x != null) {
y = x.toUpperCase();
} else {
y = “none”;
}
val x = Option(getString())
val y =
x.map{_.toUpperCase}.
getOrElse(“none”)
Java 7- Scala
Null Checking Idioms
String x = getString();
String y = x.toUpperCase();
val x = Option(getString())
val y = x.toUpperCase
Java 7- Scala
Okay until it actually runs Compilation error
• Use static analyzers. Not perfect but practical
enough
• Do not use null at all. Define empty values. Use
alternative languages such as Scala
Possible Solutions for Null
Game is not over yet
Long time ago in the Java type system,
Java Array and Type Variance
String[] strings = new String[10];
Object[] objects = strings;
objects[0] = 0;
Compiled well but throw exception in a runtime
Why?
Type Variance
Set[Dog] <: Set[Animal] ?
Assume Dog is a subclass of Animal
Could a set of Dog be a subclass of a set of Animal?
Dog <: Animal
Type Variance
Set[Dog] <: Set[Animal]
Assume Dog is a subclass of Animal
If Set is covariant
Dog <: Animal
If Set is contravariant
Set[Animal] <: Set[Dog]
Type Variance in Action
Assume Dog <: Animal, Rose <: Flower
Animal RoseDog Flower
We can use a function Animal -> Rose as if it were a function Dog -> Flower
Type Variance in Action
Assume Dog <: Animal, Rose <: Flower
Animal RoseDog Flower
val foo : Animal => Rose = { x => …}
val bar : Dog => Flower = foo
Type Variance in Action
Assume Dog <: Animal, Rose <: Flower
Animal RoseDog Flower
val foo : Function1[Animal,Rose] = { x => …}
val bar : Function1[Dog,Flower] = foo
trait Function1[-T,+R]
Java Array Revisited
String[] strings = new String[10];
Object[] objects = strings;
objects[0] = 0;
Java Array is covariant which means
Reading from Java Array is always safe
Writing to Java Array is not always safe
Type Variance Revisited
Variance Explanation Reading Writing
Set[E]
Invariance
Set[Animal] should be Set[Animal]
Set[Dog] should be Set[Dog]
Safe Safe
Set[+E]
Covariance
Set[Animal] can be Set[Dog]
Set[Dog] should be Set[Dog]
Safe Unsafe
Set[-E]
Contravariance
Set[Animal] should be Set[Animal]
Set[Dog] can be Set[Animal]
Unsafe Safe
Assume Dog is a subclass of Animal
• Use generics. Avoid raw types. Avoid arrays
• Use alternative type-safe languages such as
Scala
Possible Solutions for Java Type Holes
Deus ex machina
Just use Scala
http://scala-lang.org

More Related Content

What's hot

Software Development Lab test 3
Software Development Lab test 3 Software Development Lab test 3
Software Development Lab test 3 Alvin Chin
 
Pontificating quantification
Pontificating quantificationPontificating quantification
Pontificating quantificationAaron Bedra
 
NSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to SwiftNSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to SwiftAndreas Blick
 
String interpolation
String interpolationString interpolation
String interpolationKnoldus Inc.
 
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...Doris Chen
 
Java Tutorial Lab 5
Java Tutorial Lab 5Java Tutorial Lab 5
Java Tutorial Lab 5Berk Soysal
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUIBongwon Lee
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?Sarah Mount
 
Making friends with TDD
Making friends with TDDMaking friends with TDD
Making friends with TDDJohn Cleary
 
Annotation based null analysis in Eclipse JDT
Annotation based null analysis in Eclipse JDTAnnotation based null analysis in Eclipse JDT
Annotation based null analysis in Eclipse JDTEclipse Day India
 
Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Ganesh Samarthyam
 
Futzing with actors (etc.)
Futzing with actors (etc.)Futzing with actors (etc.)
Futzing with actors (etc.)league
 
Lambda functions in java 8
Lambda functions in java 8Lambda functions in java 8
Lambda functions in java 8James Brown
 

What's hot (20)

Introducing Akka
Introducing AkkaIntroducing Akka
Introducing Akka
 
Software Development Lab test 3
Software Development Lab test 3 Software Development Lab test 3
Software Development Lab test 3
 
Pontificating quantification
Pontificating quantificationPontificating quantification
Pontificating quantification
 
NSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to SwiftNSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to Swift
 
String interpolation
String interpolationString interpolation
String interpolation
 
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
 
Java Tutorial Lab 5
Java Tutorial Lab 5Java Tutorial Lab 5
Java Tutorial Lab 5
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Developing a new Epsilon EMC driver
Developing a new Epsilon EMC driverDeveloping a new Epsilon EMC driver
Developing a new Epsilon EMC driver
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
 
Making friends with TDD
Making friends with TDDMaking friends with TDD
Making friends with TDD
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
 
Annotation based null analysis in Eclipse JDT
Annotation based null analysis in Eclipse JDTAnnotation based null analysis in Eclipse JDT
Annotation based null analysis in Eclipse JDT
 
Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8
 
Akka 2.0 Reloaded
Akka 2.0 ReloadedAkka 2.0 Reloaded
Akka 2.0 Reloaded
 
Futzing with actors (etc.)
Futzing with actors (etc.)Futzing with actors (etc.)
Futzing with actors (etc.)
 
Lambda functions in java 8
Lambda functions in java 8Lambda functions in java 8
Lambda functions in java 8
 

Similar to Fire in the type hole

(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Orleankka Intro Circa 2015
Orleankka Intro Circa 2015Orleankka Intro Circa 2015
Orleankka Intro Circa 2015Yevhen Bobrov
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesDebasish Ghosh
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldWerner Hofstra
 
Next generation actors with Akka
Next generation actors with AkkaNext generation actors with Akka
Next generation actors with AkkaJohan Andrén
 
Haskell for Scala-ists
Haskell for Scala-istsHaskell for Scala-ists
Haskell for Scala-istschriseidhof
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard LibrarySantosh Rajan
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 
Functional programming with F#
Functional programming with F#Functional programming with F#
Functional programming with F#Remik Koczapski
 
Types by Adform Research, Saulius Valatka
Types by Adform Research, Saulius ValatkaTypes by Adform Research, Saulius Valatka
Types by Adform Research, Saulius ValatkaVasil Remeniuk
 
Python introduction
Python introductionPython introduction
Python introductionleela rani
 
Functional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsFunctional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsCodeOps Technologies LLP
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introductioncaswenson
 
Beyond xUnit example-based testing: property-based testing with ScalaCheck
Beyond xUnit example-based testing: property-based testing with ScalaCheckBeyond xUnit example-based testing: property-based testing with ScalaCheck
Beyond xUnit example-based testing: property-based testing with ScalaCheckFranklin Chen
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOJorge Vásquez
 

Similar to Fire in the type hole (20)

Java introduction
Java introductionJava introduction
Java introduction
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Orleankka Intro Circa 2015
Orleankka Intro Circa 2015Orleankka Intro Circa 2015
Orleankka Intro Circa 2015
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rules
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereld
 
Next generation actors with Akka
Next generation actors with AkkaNext generation actors with Akka
Next generation actors with Akka
 
Haskell for Scala-ists
Haskell for Scala-istsHaskell for Scala-ists
Haskell for Scala-ists
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Type Classes
Type ClassesType Classes
Type Classes
 
ppopoff
ppopoffppopoff
ppopoff
 
Functional programming with F#
Functional programming with F#Functional programming with F#
Functional programming with F#
 
Types by Adform Research, Saulius Valatka
Types by Adform Research, Saulius ValatkaTypes by Adform Research, Saulius Valatka
Types by Adform Research, Saulius Valatka
 
Python introduction
Python introductionPython introduction
Python introduction
 
Functional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsFunctional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and Streams
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 
130706266060138191
130706266060138191130706266060138191
130706266060138191
 
Meet scala
Meet scalaMeet scala
Meet scala
 
Beyond xUnit example-based testing: property-based testing with ScalaCheck
Beyond xUnit example-based testing: property-based testing with ScalaCheckBeyond xUnit example-based testing: property-based testing with ScalaCheck
Beyond xUnit example-based testing: property-based testing with ScalaCheck
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIO
 

Recently uploaded

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

Fire in the type hole

  • 1. Fire in the type hole Why you shouldn’t trust a Java compiler in everything Heejong Lee (@heejongl)
  • 2. – Mr. Unknown Java Compiler “Do you trust me?”
  • 3. Computer Science [Tool] The Study of Programming Languages [Method] The Study of Algorithm
  • 4. • Reliable safety net for programming systems • Statically verifying that something wrong will not happen in the runtime • Blazingly fast A great step forward to the better world : Type System
  • 6. Type System Safe programs Unsafe programs Typed programs
  • 7. • Verified by a type system implies a program will never violate the rule that the type system defines • Failed by a type system does not implies a program will violate the rule that the type system defines • Possibly, there exists a program which is safe but a type system cannot verify its safety Type System
  • 10. Type System 1:int + “hello”
  • 11. Type System 1:int + “hello”:string
  • 12. Type System 1:int + “hello”:string May cause segmentation fault, exception, unexpected behavior in some languages
  • 13. Type System (1:int + “hello”:string):string In Java, 1 will be automatically converted to string
  • 14. Type System (1:int + “hello”:string):int Or, error: incompatible types: String cannot be converted to int
  • 15. Type System String foo(int x) { int y = 10 + x; return y.toString(); } void bar() { foo(10); } foo : int -> string = + toString bar : unit -> unit foo( )
  • 17. One value to rule types all
  • 18. • The most catastrophic design decision ever made • Tony Hoare introduced Null references in ALGOL W back in 1965 “simply because it was so easy to implement” • Can be an any type, ultimately unarm the Java type system Null
  • 19. foo : string -> string bar : unit -> unit foo( ) Type System String foo(String x) { return x.toUpperCase(); } void bar() { String s = null; foo(s); } toUpperCase
  • 20. foo : string -> string bar : unit -> unit foo( ) Type System String foo(String x) { return x.toUpperCase(); } void bar() { String s = null; foo(s); } toUpperCase
  • 21. • Impossible in general • However, recent programming languages introduce a typed null : Option[T] in Scala, Optional<T> in Java8 How could we survive Null attacks
  • 22. Null Checking Idioms String x = getString(); String y = null; if(x != null) { y = x.toUpperCase(); } else { y = “none”; } val x = Option(getString()) val y = x.map{_.toUpperCase}. getOrElse(“none”) Java 7- Scala
  • 23. Null Checking Idioms String x = getString(); String y = x.toUpperCase(); val x = Option(getString()) val y = x.toUpperCase Java 7- Scala Okay until it actually runs Compilation error
  • 24. • Use static analyzers. Not perfect but practical enough • Do not use null at all. Define empty values. Use alternative languages such as Scala Possible Solutions for Null
  • 25. Game is not over yet
  • 26. Long time ago in the Java type system,
  • 27. Java Array and Type Variance String[] strings = new String[10]; Object[] objects = strings; objects[0] = 0; Compiled well but throw exception in a runtime Why?
  • 28. Type Variance Set[Dog] <: Set[Animal] ? Assume Dog is a subclass of Animal Could a set of Dog be a subclass of a set of Animal? Dog <: Animal
  • 29. Type Variance Set[Dog] <: Set[Animal] Assume Dog is a subclass of Animal If Set is covariant Dog <: Animal If Set is contravariant Set[Animal] <: Set[Dog]
  • 30. Type Variance in Action Assume Dog <: Animal, Rose <: Flower Animal RoseDog Flower We can use a function Animal -> Rose as if it were a function Dog -> Flower
  • 31. Type Variance in Action Assume Dog <: Animal, Rose <: Flower Animal RoseDog Flower val foo : Animal => Rose = { x => …} val bar : Dog => Flower = foo
  • 32. Type Variance in Action Assume Dog <: Animal, Rose <: Flower Animal RoseDog Flower val foo : Function1[Animal,Rose] = { x => …} val bar : Function1[Dog,Flower] = foo trait Function1[-T,+R]
  • 33. Java Array Revisited String[] strings = new String[10]; Object[] objects = strings; objects[0] = 0; Java Array is covariant which means Reading from Java Array is always safe Writing to Java Array is not always safe
  • 34. Type Variance Revisited Variance Explanation Reading Writing Set[E] Invariance Set[Animal] should be Set[Animal] Set[Dog] should be Set[Dog] Safe Safe Set[+E] Covariance Set[Animal] can be Set[Dog] Set[Dog] should be Set[Dog] Safe Unsafe Set[-E] Contravariance Set[Animal] should be Set[Animal] Set[Dog] can be Set[Animal] Unsafe Safe Assume Dog is a subclass of Animal
  • 35. • Use generics. Avoid raw types. Avoid arrays • Use alternative type-safe languages such as Scala Possible Solutions for Java Type Holes
  • 36. Deus ex machina Just use Scala http://scala-lang.org