nullaway
하는 일
이 스킬은 NullAway가 보고한 오류를 AI가 고치도록 안내합니다. NullAway는 Java 코드에서 값이 null일 수 있는 곳을 찾는 도구입니다. 널 주석을 추가하거나 업데이트하는 개발자를 위한 스킬입니다.
사용하는 경우
- ✓NullAway가 null일 수 있는 값에 대한 오류를 보고할 때.
- ✓Java 파일에 @NullMarked를 추가해서 새 경고를 고쳐야 할 때.
- ✓기존 코드를 깨지 않고 nullable 공급자나 관찰 가능한 값을 전달해야 할 때.
스킬 링크
https://github.com/chromium/chromium/blob/main/agents/skills/nullaway/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“제 Java 파일에 NullAway 오류가 나타납니다. 앱 동작을 바꾸지 않고 고쳐 주실 수 있나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
AI는 null일 수 있는 각 값이 어떻게 쓰이는지 살펴봅니다. 그다음 검사기를 통과시키는 가장 가벼운 방법을 골라 안전한 검사나 단언을 추가합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 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
자주 묻는 질문
NullAway란 무엇인가요?
값이 비어 있을 수 있는 곳을 Java 코드에서 찾아내는 검사 도구이며, 이런 곳은 충돌을 일으킬 수 있습니다.
수정이 앱 동작을 바꾸나요?
오래된 코드를 옮길 때는 동작 변경을 피하려고 노력합니다. 새 로직보다 작은 단언을 선호합니다.
새 코드에만 해당하나요?
아니요. 오래된 코드를 null 표시 코드로 옮기는 작업과, 이미 쓰고 있는 파일에 새 코드를 쓰는 작업 모두를 다룹니다.
상세 정보
작성자의 원본 설명
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
인기도
- GitHub 스타
- 25k
- 순위
- #10062
- 라이선스
- BSD-3-Clause
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
fuzzing
25k에이전트가 많은 무작위 입력을 코드에 넣어 충돌과 버그를 찾는 퍼즈 테스트를 C++ 코드용으로 작성하도록 돕습니다.
gn-deps-debugging
25k에이전트가 GN 빌드 파일의 누락되거나 잘못된 의존성으로 생기는 빌드 오류를 고치도록 돕습니다. 넓고 불필요한 의존성은 추가하지 않습니다.
java-memory-leaks
25k에이전트가 LeakCanary의 누수 보고서를 읽어 Android 앱의 Java 메모리 누수를 찾고 고치도록 돕습니다.
jni-type-conversion
25k에이전트가 Android 코드에서 수동으로 작성한 Java와 C++ 간 변환 코드를 더 간단한 @JniType 주석으로 바꾸도록 돕습니다.