nullaway
ما الذي تفعله
توجه هذه المهارة الذكاء الاصطناعي لإصلاح أخطاء NullAway، وهي أداة تجد الأماكن التي قد تكون فيها القيمة فارغة في شيفرة Java. وهي مخصصة للمطورين الذين يضيفون أو يحدّثون تعليقات القيم الفارغة.
متى تستخدمها
- ✓عندما يبلغ NullAway عن خطأ بسبب قيمة قد تكون فارغة.
- ✓عندما تضيف @NullMarked إلى ملف Java وتحتاج إلى إصلاح التحذيرات الجديدة.
- ✓عندما تحتاج إلى تمرير مزوّد أو قيمة قابلة للفراغ دون أن تكسر الشيفرة.
رابط المهارة
https://github.com/chromium/chromium/blob/main/agents/skills/nullaway/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“يعرض NullAway خطأً في ملف Java لدي. هل يمكنك إصلاحه دون تغيير طريقة عمل التطبيق؟”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
ينظر الذكاء الاصطناعي إلى كيفية استخدام كل قيمة قد تكون فارغة، ثم يضيف فحصًا آمنًا أو تأكيدًا، مختارًا أخف خيار يرضي الفاحص.
المحتوى التقني (ملف 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؟
NullAway فاحص يبحث في شيفرة Java عن الأماكن التي قد تكون فيها القيمة فارغة، وهو ما قد يسبب أعطالًا.
هل سيغيّر الإصلاح طريقة عمل تطبيقي؟
تحاول المهارة تجنب تغيير السلوك عند ترحيل شيفرة قديمة، وتفضّل التأكيدات الصغيرة على منطق جديد.
هل هي للشيفرة الجديدة فقط؟
لا. تغطي ترحيل الشيفرة القديمة إلى الشيفرة ذات التعليقات، وكتابة شيفرة جديدة في ملفات تستخدمها أصلًا.
التفاصيل
الوصف الأصلي من المؤلف
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
- آخر تحديث
- 2/11/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
fuzzing
25kيساعد وكيلك على كتابة اختبارات فازينغ تمرر مدخلات عشوائية كثيرة إلى الشيفرة لاكتشاف الأعطال والأخطاء في شيفرة C++.
gn-deps-debugging
25kيساعد وكيلك على إصلاح أخطاء البناء الناتجة عن تبعيات ناقصة أو خاطئة في ملفات بناء GN، دون إضافة تبعيات واسعة وغير لازمة.
java-memory-leaks
25kيساعد وكيلك على إيجاد تسريبات الذاكرة في تطبيقات Android المكتوبة بـ Java وإصلاحها، عبر قراءة تقارير التسريب من LeakCanary.
jni-type-conversion
25kيساعد وكيلك على استبدال شيفرة التحويل اليدوي بين Java وC++ بتعليقات @JniType أبسط في شيفرة Android.
مهارات مشابهة
diffs
394kيتيح لوكيلك إنتاج فرق تعديلات حقيقي يمكن مشاركته، كرابط عرض أو ملف صورة، بدلاً من ملخص مكتوب يدوياً.
coding-agent
394kيساعد وكيلك على تسليم مهمة برمجة كبيرة إلى Codex أو Claude Code أو OpenCode كعامل في الخلفية، ثم متابعة تقدمها.
gh-issues
394kيساعد وكيلك على إيجاد مشكلات GitHub واختيار ما ستعمل عليه، وفتح طلبات سحب بالإصلاحات، ومتابعة تعليقات المراجعة.