Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Null the abyss
Search
Keishin Yokomaku
May 13, 2015
Technology
3.3k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Null the abyss
We need to look after 'null' value carefully.
Keishin Yokomaku
May 13, 2015
More Decks by Keishin Yokomaku
See All by Keishin Yokomaku
Base64 in Android
keithyokoma
0
58
One screen, many BottomSheets
keithyokoma
0
470
LazyColumnのitemがViewPortの中で占める領域の割合を知りたい
keithyokoma
0
760
Build apps for Cars
keithyokoma
0
600
Save the state
keithyokoma
0
640
Either in Kotlin
keithyokoma
0
660
持続的なアプリ開発のためのDXを支える技術
keithyokoma
2
5.6k
Make the objects serializable with kotlinx.serialization
keithyokoma
0
5.4k
Kotlin で書く Gradle Custom Tasks
keithyokoma
0
590
Other Decks in Technology
See All in Technology
AIエージェントを雇う前に決める5つのこと
knishioka
1
130
markdown-poster Introduction
kazamori
0
450
VPCでもFloatingIPを使いたいんだ
y_kotani
1
140
1000⼈規模のClaude Enterprise運⽤を「Oktaのグループ」と「Slack」に集約する
sansantech
PRO
1
560
Level Up Your CDK DX: 5 Tools I’ve Been Building
gotok365
2
160
Bet AI Day 2026丨バクラク Autopilot、業務システムの再設計
layerx
PRO
1
600
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
55k
Genie Code ワークショップ 応用編 / Genie-Code-Workshop-advanced
databricksjapan
PRO
0
230
Genie Code ワークショップ 基礎編 / Genie-Code-Workshop-fundamental
databricksjapan
PRO
0
260
Backstageでつくるセルフサービスな社内開発基盤
kikunosuke75
1
150
PdMをやめて、 "プロダクトビルダー"という 働き方に変えました / PdM to Product Builder
shikichee
2
590
When Token Pruning is Worse than Random: Understanding Visual Token Information in VLLMs
sansantech
PRO
0
220
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
4 Signs Your Business is Dying
shpigford
187
23k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
660
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
430
Ethics towards AI in product and experience design
skipperchong
2
360
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
4
540
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
490
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Automating Front-end Workflow
addyosmani
1369
210k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Transcript
Null, the Abyss @KeithYokoma - Drivemode, Inc. potatotips #17
KeithYokoma Keishin Yokomaku Drivemode, Inc. Android Engineer GitHub: https://github.com/KeithYokoma Qiita:
http://qiita.com/KeithYokoma e-Book: http://amzn.to/1mZNydv
None
˒ˑˑˑˑ
None
None
˒ˑˑˑˑ ˒ˑˑˑˑ ˒ˑˑˑˑ
–Someone “A lot of sadness is coming from NullPointerException”
Avoid NullPointerException • Null check for nullable value • Using
support annotation • Using NullObject pattern • Returning null value • Null abyss in Android
Null check statement public void method(Object arg) { if (arg
== null) { throw new NullPointerException(); } // … }
Null check statement public void method(Object arg) { if (arg
== null) { throw new NullPointerException(); } // … }
Null check statement ✓ Easy and basic way to avoid
NPE ✗ Too many checks is bad for performance ✗ Need documentation for nullity ✗ Failure at runtime
Support Annotations public void method(@Nullable Object arg) { if (arg
== null) { Log.w(“Logger”, “Nothing I can do.”) return; } // … }
Support Annotations public void method(@Nullable Object arg) { if (arg
== null) { Log.w(“Logger”, “Nothing I can do.”) return; } // … }
Support Annotations ✓ Gain Lint support for nullity ✓ Users
can understand about nullity ✗ Still have possibility of null value ✗ Failure at runtime
Using NullObject pattern ✓ No possibility of null value ✓
No change to get NullPointerException ✗ Need to learn architecture
Using NullObject pattern Bad Practice public enum NavMenu { HOME(R.id.home),
PROFILE(R.id.profile); public static NavMenu get(int id) { for (NavMenu menu : values()) { if (menu.id == id) return menu; } return null; } }
Using NullObject pattern Good Practice public enum NavMenu { HOME(R.id.home),
PROFILE(R.id.profile), NONE(-1); public static NavMenu get(int id) { for (NavMenu menu : values()) { if (menu.id == id) return menu; } return NONE; } }
Returning null value Bad Practice public List<Result> get(int count) {
if (something went wrong) { return null; } //… }
Returning null value Good Practice public List<Result> get(int count) {
if (something went wrong) { return new ArrayList<>(); } //… }
Returning null value Other Good Practice public List<Result> get(int count)
{ if (something went wrong) { throw new SomeException(“Request failed for some reason.”); } //… }
Returning null value • “null” means value is absent •
Empty collection instead of null • Failure for throwing Exception
Null abyss in Android • Some support API returns “null”
• e.g. MediaSessionCompat • You need to verify nullity for those APIs…
None
–Someone “When you gaze into null, null gazes into you”
For more details… • Effective Java
Null, the Abyss @KeithYokoma - Drivemode, Inc. potatotips #17