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.2k
1
Share
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
47
One screen, many BottomSheets
keithyokoma
0
450
LazyColumnのitemがViewPortの中で占める領域の割合を知りたい
keithyokoma
0
730
Build apps for Cars
keithyokoma
0
570
Save the state
keithyokoma
0
610
Either in Kotlin
keithyokoma
0
630
持続的なアプリ開発のためのDXを支える技術
keithyokoma
2
5.5k
Make the objects serializable with kotlinx.serialization
keithyokoma
0
5.3k
Kotlin で書く Gradle Custom Tasks
keithyokoma
0
580
Other Decks in Technology
See All in Technology
【技術書典20】OpenFOAM(自宅で深める流体解析)流れと熱移動(2)
kamakiri1225
0
290
Revisiting [CLS] and Patch Token Interaction in Vision Transformers
yu4u
0
400
Microsoft 365 / Microsoft 365 Copilot : 自分の状態を確認する「ラベル」について
taichinakamura
0
370
AI活用時代の事業判断高度化を導くエンジニアリング基盤 / 20260424 Atsushi Funahashi
shift_evolve
PRO
2
100
Arcana: Production-Ready RAG in Elixir @ ElixirConf EU 2026
georgeguimaraes
0
120
Pure Intonation on Browser: Building a Sequencer with Ruby
nagachika
0
170
Building a Standalone Programming Environment
harukasan
PRO
1
100
需要創出(Chatwork)×供給(BPaaS) フライホイールとMoat 実行能力の最適配置とAI戦略
kubell_hr
0
1k
AI時代のガードレールとしてのAPIガバナンス
nagix
0
310
AWS Agent Registry の基礎・概要を理解する/aws-agent-registry-intro
ren8k
3
410
エージェントスキルを作って自分のインプットに役立てよう
tsubakimoto_s
0
470
20260428_Product Management Summit_Loglass_JoeHirose
loglassjoe
3
4k
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
310
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Skip the Path - Find Your Career Trail
mkilby
1
110
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
540
Mobile First: as difficult as doing things right
swwweet
225
10k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
120
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
55k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
340
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
680
Utilizing Notion as your number one productivity tool
mfonobong
4
290
Deep Space Network (abreviated)
tonyrice
0
120
How to Talk to Developers About Accessibility
jct
2
180
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