본문으로 건너뛰기
Skillpedia
일반 코딩25k · #10062

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/chromium/chromium/blob/main/agents/skills/nullaway/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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. Use assert when storing or returning values. Use if guards occasionally if it helps avoid assertions, but avoid changing the logic.
  • New Code (and modifying already @NullMarked code):
    • 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 @Nullable values. 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 @Nullable values immediately: Use NullUtil.assumeNonNull(x).
    • Example:
      var value = mSupplier.get();
      assumeNonNull(value);
      value.doSomething();
      
    • Why: If it is null, it will NPE on the dereference anyway. assumeNonNull is 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().
  • Passing @Nullable values to non-null parameters: First, look into the call tree of the receiver class and see if that parameter should be annotated as @Nullable or 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 Java assert x != null; on a preceding line before passing or storing it.

    [!CAUTION] NEVER use assumeNonNull(x) to pass a @Nullable value to a non-null parameter or to return it from a non-nullable method. This is STRICTLY FORBIDDEN. You MUST use a Java assert on a preceding line to add a runtime check.

    • Bad Example:
      mReceiver.setSomething(assumeNonNull(nullableValue));
      
    • Good Example:
      assert nullableValue != null;
      mReceiver.setSomething(nullableValue);
      
  • Returning @Nullable values 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 Java assert x != null; on a preceding line before returning the value. Using assumeNonNull(x) inline within a return statement is strictly forbidden.
    • Bad Example:
      return assumeNonNull(nullableValue);
      
    • Good Example:
      assert nullableValue != null;
      return nullableValue;
      
  • 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 != null on Supplier.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 @Nullable and callers should handle it, rather than asserting non-null immediately.

4. Handling Suppliers and Generics

  • Problem: Passing a Supplier<@Nullable T> to a constructor that expects Supplier<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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬