-
Notifications
You must be signed in to change notification settings - Fork 1k
refactor: declare org.testng.internal null-marked #3396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
57de471
03c6d19
5e4756a
4b0bb74
dbbe524
3cc9638
57c25f0
a2e9939
58fdeaa
2d55053
c31a839
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ protected MultiMap(boolean isSorted) { | |
|
|
||
| protected abstract C createValue(); | ||
|
|
||
| public boolean put(K key, V method) { | ||
| public boolean put(@Nullable K key, V method) { | ||
| AtomicBoolean exists = new AtomicBoolean(true); | ||
| return m_objects | ||
| .computeIfAbsent( | ||
|
|
@@ -35,15 +35,15 @@ public boolean put(K key, V method) { | |
| && exists.get(); | ||
| } | ||
|
|
||
| public C get(K key) { | ||
| public C get(@Nullable K key) { | ||
| return m_objects.computeIfAbsent(key, k -> createValue()); | ||
| } | ||
|
|
||
| public Set<K> keySet() { | ||
| return new HashSet<>(m_objects.keySet()); | ||
| } | ||
|
|
||
| public boolean containsKey(K k) { | ||
| public boolean containsKey(@Nullable K k) { | ||
| return m_objects.containsKey(k); | ||
| } | ||
|
|
||
|
|
@@ -68,7 +68,7 @@ public int size() { | |
| return m_objects.size(); | ||
| } | ||
|
|
||
| public boolean remove(K key, V value) { | ||
| public boolean remove(@Nullable K key, V value) { | ||
| return get(key).remove(value); | ||
|
Comment on lines
+71
to
72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- MultiMap.java structure ---'
wc -l testng-collections/src/main/java/org/testng/collections/MultiMap.java
ast-grep outline testng-collections/src/main/java/org/testng/collections/MultiMap.java || true
printf '%s\n' '--- Relevant implementation ---'
sed -n '1,150p' testng-collections/src/main/java/org/testng/collections/MultiMap.java
printf '%s\n' '--- Relevant tests and usages ---'
rg -n -C 3 'remove\(.*,' testng-collections/src/test testng-collections/src/main 2>/dev/null || true
rg -n -C 3 'class MultiMap|MultiMap<' testng-collections/src/test testng-collections/src/main 2>/dev/null || trueRepository: testng-team/testng Length of output: 22859 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
source = Path("testng-collections/src/main/java/org/testng/collections/MultiMap.java").read_text()
assert "return get(key).remove(value);" in source
# Model the relevant Map.computeIfAbsent behavior for an absent key.
objects = {}
key, value = "absent", "v"
bucket = objects.get(key)
if bucket is None:
bucket = []
objects[key] = bucket
removed = value in bucket
if removed:
bucket.remove(value)
assert removed is False
assert key in objects
assert len(objects) == 1
print("Absent-key removal returns false and leaves one empty bucket.")
PY
printf '%s\n' '--- Test assertions ---'
sed -n '72,86p' testng-collections/src/test/java/org/testng/collections/MultiMapTest.javaRepository: testng-team/testng Length of output: 692 Do not create a bucket during removal.
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
@@ -78,7 +78,7 @@ public boolean remove(K key, V value) { | |
| * @param key the key to drop. | ||
| * @return the values that were held, or {@code null} when the key was not present. | ||
| */ | ||
| public @Nullable C removeAll(K key) { | ||
| public @Nullable C removeAll(@Nullable K key) { | ||
| return m_objects.remove(key); | ||
| } | ||
|
|
||
|
|
@@ -90,7 +90,7 @@ public Collection<C> values() { | |
| return m_objects.values(); | ||
| } | ||
|
|
||
| public boolean putAll(K k, Collection<? extends V> values) { | ||
| public boolean putAll(@Nullable K k, Collection<? extends V> values) { | ||
| boolean result = false; | ||
| for (V v : values) { | ||
| result = put(k, v) || result; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /** The engine behind the public API: test methods, parameters, configuration and scheduling. */ | ||
| @NullMarked | ||
| package org.testng.internal; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: testng-team/testng
Length of output: 7393
🏁 Script executed:
Repository: testng-team/testng
Length of output: 50375
🏁 Script executed:
Repository: testng-team/testng
Length of output: 689
🏁 Script executed:
Repository: testng-team/testng
Length of output: 37378
🏁 Script executed:
Repository: testng-team/testng
Length of output: 4783
🏁 Script executed:
Repository: testng-team/testng
Length of output: 304
🏁 Script executed:
Repository: testng-team/testng
Length of output: 4726
🏁 Script executed:
Repository: testng-team/testng
Length of output: 227
Propagate nullable-key types to the collection views.
The
org.testng.collectionspackage is@NullMarked, butput(@nullableK, ...)permits null keys whilekeySet()andentrySet()expose non-nullK. Updatem_objects,keySet(), andentrySet()to use@Nullable K, or reject null keys.🤖 Prompt for AI Agents