nullaway
Fungsinya
Skill ini memandu AI Anda untuk memperbaiki error dari NullAway, alat yang menemukan kemungkinan nilai null dalam kode Java. Cocok untuk pengembang yang menambahkan atau memperbarui anotasi null.
Kapan dipakai
- ✓Saat NullAway melaporkan error tentang nilai yang mungkin null.
- ✓Saat Anda menambahkan @NullMarked ke file Java dan perlu memperbaiki peringatan baru.
- ✓Saat Anda perlu meneruskan supplier atau nilai observable yang nullable tanpa merusak kode.
Link skill
https://github.com/chromium/chromium/blob/main/agents/skills/nullaway/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
“NullAway menampilkan error pada file Java saya. Bisakah Anda memperbaikinya tanpa mengubah cara aplikasi bekerja?”
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
AI melihat bagaimana setiap nilai yang mungkin null digunakan. Lalu AI menambahkan pemeriksaan aman atau assertion, dengan memilih opsi paling ringan yang memenuhi pemeriksa.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Core Principles
1. Migration to @NullMarked vs New Code
The approach differs significantly depending on whether you are migrating
existing code to @NullMarked or writing new code in an already @NullMarked
context:
- Migration to
@NullMarked:- Goal: Satisfy the static analyzer while minimizing functional changes to avoid regressions.
- Practice: Use
NullUtil.assumeNonNull()when dereferencing immediately to satisfy the analyzer without runtime overhead. Useassertwhen storing or returning values. Useifguards occasionally if it helps avoid assertions, but avoid changing the logic.
- New Code (and modifying already
@NullMarkedcode):- Goal: Build robust, null-safe components from the ground up.
- Practice: Be more liberal with
asserts to enforce contracts. Rely on correct annotations (or their absence for implicit@NonNull) and only use null guards for@Nullablevalues.assumeNonNull()should generally not be used for new code.
2. No Functional Changes (For Migration)
- Rule: When migrating existing code, avoid adding new throwing runtime checks where they did not exist before, unless guided by the rules below.
3. assumeNonNull vs assert != null
The choice between assumeNonNull and Java assert depends on how the value is
used:
- Dereferencing
@Nullablevalues immediately: UseNullUtil.assumeNonNull(x).- Example:
var value = mSupplier.get(); assumeNonNull(value); value.doSomething(); - Why: If it is null, it will NPE on the dereference anyway.
assumeNonNullis a no-op that satisfies the analyzer without adding redundant runtime checks. - Style Rule:
assumeNonNull()should be on a separate line, almost always, rather than used inline. - Note: This rule is primarily for migrations to avoid functional
changes. For new code, rely on correct annotations and avoid
assumeNonNull().
- Example:
- Passing
@Nullablevalues to non-null parameters: First, look into the call tree of the receiver class and see if that parameter should be annotated as@Nullableor not. If it can natively handle null, update the method signature instead of adding an assertion. If it strictly requires a non-null value, THEN you MUST use a Javaassert x != null;on a preceding line before passing or storing it.[!CAUTION] NEVER use
assumeNonNull(x)to pass a@Nullablevalue to a non-null parameter or to return it from a non-nullable method. This is STRICTLY FORBIDDEN. You MUST use a Javaasserton a preceding line to add a runtime check.- Bad Example:
mReceiver.setSomething(assumeNonNull(nullableValue)); - Good Example:
assert nullableValue != null; mReceiver.setSomething(nullableValue);
- Bad Example:
- Returning
@Nullablevalues from non-nullable methods: First, consider if the method's return type can be safely updated to@Nullable. If it cannot (e.g., because it implements an interface or strictly enforces a non-null contract), you MUST use a Javaassert x != null;on a preceding line before returning the value. UsingassumeNonNull(x)inline within a return statement is strictly forbidden.- Bad Example:
return assumeNonNull(nullableValue); - Good Example:
assert nullableValue != null; return nullableValue;
- Bad Example:
- Why: Asserts add a runtime check (active in tests/debug) which is an
acceptable functional change. We rely on instrumentation tests to validate
these changes.
- Deep Investigation Rule: Before asserting or assuming non-null for a
passed value, investigate the call tree. If the method being called can be
updated to consider the parameter
@Nullable, prefer updating the method signature over adding an assertion. - Warning: Be careful with
assert value != nullonSupplier.get()during initialization. If the supplier value is set LATER (as is common with UI wiring), the assert might fail immediately during construction. In such cases, the getter should return@Nullableand callers should handle it, rather than asserting non-null immediately.
- Deep Investigation Rule: Before asserting or assuming non-null for a
passed value, investigate the call tree. If the method being called can be
updated to consider the parameter
4. Handling Suppliers and Generics
- Problem: Passing a
Supplier<@Nullable T>to a constructor that expectsSupplier<T>(non-nullable), or vice
Pertanyaan umum
Apa itu NullAway?
NullAway adalah pemeriksa yang mencari tempat nilai bisa kosong dalam kode Java, yang bisa menyebabkan crash.
Apakah perbaikan akan mengubah cara aplikasi berperilaku?
Skill berusaha menghindari perubahan perilaku saat memigrasikan kode lama. Skill lebih memilih assertion kecil daripada logika baru.
Apakah ini hanya untuk kode baru?
Tidak. Skill mencakup migrasi kode lama ke kode yang bertanda null dan penulisan kode baru di file yang sudah memakainya.
Detail
Deskripsi asli dari pembuat
Guide for resolving NullAway static analysis errors. Best practices for: - Passing ObservableSupplier/Supplier<@Nullable T> - Dereferencing potentially @Nullable values - Adding @NullMarked to Java code
repo: chromium/chromium
Popularitas
- Bintang GitHub
- 25k
- Peringkat
- #10062
- Lisensi
- BSD-3-Clause
- Diperbarui
- 2/11/2026
Komentar
- …
Skill lain dari repositori ini
fuzzing
25kMembantu agent Anda menulis tes fuzz yang memasukkan banyak input acak ke dalam kode untuk menemukan crash dan bug pada kode C++.
gn-deps-debugging
25kMembantu agent Anda memperbaiki error build akibat dependensi yang hilang atau salah pada file build GN, tanpa menambahkan dependensi luas yang tidak diperlukan.
java-memory-leaks
25kMembantu agent Anda menemukan dan memperbaiki kebocoran memori Java pada aplikasi Android dengan membaca laporan kebocoran dari LeakCanary.
jni-type-conversion
25kMembantu agent Anda mengganti kode konversi Java ke C++ yang ditulis manual dengan anotasi @JniType yang lebih sederhana pada kode Android.
Skill serupa
diffs
394kMemungkinkan agent Anda menghasilkan diff perubahan yang nyata dan dapat dibagikan sebagai tautan viewer atau file gambar, bukan ringkasan yang ditulis manual.
coding-agent
394kMembantu agent Anda menyerahkan pekerjaan pemrograman besar ke Codex, Claude Code, atau OpenCode di latar belakang, lalu memeriksa kemajuannya.
gh-issues
394kMembantu agent Anda menemukan issue GitHub, memilih yang dikerjakan, dan membuka pull request perbaikan, termasuk tindak lanjut komentar tinjauan.