Skip to content

Instantly share code, notes, and snippets.

@cmuramoto
cmuramoto / null-safe-design.md
Created February 6, 2026 20:45
Null Safe Design

Null-Safe Navigation Operator (?.) — Design Document

Overview

Add a null-safe navigation operator (?.) to the Java language, enabling concise null-checking chains for member access and method calls. This is a compiler-only change (javac) — no JVM modifications required.

Current boilerplate:

String cityName = null;
if (person != null && person.address() != null && person.address().city != null) {
@cmuramoto
cmuramoto / primitive-struggle.md
Created February 6, 2026 19:51
Primitive Struggle

Null-Safe Navigation: Primitive Leaf Type Handling

The Problem

The null-safe operator ?. fundamentally returns "the member's value, or a null-like sentinel if the receiver is null." For reference-type members this is trivial — null serves as the sentinel. But primitive types in Java cannot be null, so the compiler must transform the result type.

@cmuramoto
cmuramoto / null-safe-navigation-full.diff
Created February 6, 2026 19:50
NullSafeNaviation-Diff
diff --git a/src/jdk.compiler/share/classes/com/sun/source/tree/NullSafeMemberSelectTree.java b/src/jdk.compiler/share/classes/com/sun/source/tree/NullSafeMemberSelectTree.java
new file mode 100644
index 00000000000..6b86746f470
--- /dev/null
+++ b/src/jdk.compiler/share/classes/com/sun/source/tree/NullSafeMemberSelectTree.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
@cmuramoto
cmuramoto / NullSafeNavigationTest.java
Created February 6, 2026 19:17
Null Safe Navigation Tests
/*
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or