Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Null the abyss
Search
Keishin Yokomaku
May 13, 2015
Technology
1
3.1k
Null the abyss
We need to look after 'null' value carefully.
Keishin Yokomaku
May 13, 2015
Tweet
Share
More Decks by Keishin Yokomaku
See All by Keishin Yokomaku
Base64 in Android
keithyokoma
0
30
One screen, many BottomSheets
keithyokoma
0
410
LazyColumnのitemがViewPortの中で占める領域の割合を知りたい
keithyokoma
0
680
Build apps for Cars
keithyokoma
0
540
Save the state
keithyokoma
0
580
Either in Kotlin
keithyokoma
0
610
持続的なアプリ開発のためのDXを支える技術
keithyokoma
2
5.3k
Make the objects serializable with kotlinx.serialization
keithyokoma
0
5.2k
Kotlin で書く Gradle Custom Tasks
keithyokoma
0
560
Other Decks in Technology
See All in Technology
セキュリティAIエージェントの現在と未来 / PSS #2 Takumi Session
flatt_security
3
1.3k
Flutter Thread Merge - Flutter Tokyo #11
itsmedreamwalker
1
130
ブラウザ拡張のセキュリティの話 / Browser Extension Security
flatt_security
0
250
Product Engineer
resilire
0
120
Active Directory 勉強会 第 6 回目 Active Directory セキュリティについて学ぶ回
eurekaberry
16
5.8k
MCP・A2A概要 〜Google Cloudで構築するなら〜
shukob
0
140
Agents IA : la nouvelle frontière des LLMs (Tech.Rocks Summit 2025)
glaforge
0
330
MAP-7thplaceSolution
yukichi0403
2
240
段階的に進める、 挫折しない自宅サーバ入門
yu_kod
5
2.2k
.NET 10 のパフォーマンス改善
nenonaninu
2
4.4k
ECMAScript仕様の最新動向: プロセスの変化と仕様のトレンド
uhyo
2
320
命名から始めるSpec Driven
kuruwic
3
810
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
72
12k
We Have a Design System, Now What?
morganepeng
54
7.9k
It's Worth the Effort
3n
187
29k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Designing for Performance
lara
610
69k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Facilitating Awesome Meetings
lara
57
6.6k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
370
Producing Creativity
orderedlist
PRO
348
40k
Into the Great Unknown - MozCon
thekraken
40
2.2k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
Visualization
eitanlees
150
16k
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