fix: expand wildcard imports (AvoidStarImport, 79 violations) - #171
Conversation
Expand all `import x.y.*;` wildcard imports to explicit imports (51 wildcard import lines across 35 files). Two static wildcard imports are kept as-is per idiomatic JUnit/Mockito style (org.junit.jupiter.api.Assertions.* and org.mockito.Mockito.*, 28 sites) and are excluded from AvoidStarImport via checkstyle.xml so the rule reflects the intended scope going forward. Closes open-policy-agent#90 Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
….random from ArithmeticBuiltins The wildcard-expansion script that generated the explicit static imports pulled in java.lang.Math.random alongside abs/ceil/floor/round, but ArithmeticBuiltins never calls a bare random(); rand.intn() uses a local java.util.Random instance instead. checkstyle's UnusedImports check cannot catch this because the local variable is also named "random", which fools its textual reference matching. Manually audited the other 34 files touched by the wildcard-import fix for the same pattern (named static import shadowed by a same-named local/field): all remaining static imports (getArg across 8 builtin files, ceil/floor/round/abs, assertArgType, assertEquals/assertTrue, assertThat/assertThatThrownBy, any/anyString/contains/eq) have genuine bare call sites and are not shadowed. Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
|
Fixed the one real defect I found on audit:
Manually audited the other 34 files this PR touches for the same shadow pattern (a newly-expanded static import matching a same-named local var/field with zero real call sites). Of those, 16 files actually contain any
No other unused statics found. Style note considered, not changed: the expansion script hoisted several files' new Local verification ( CI caveat: only the DCO check has run so far ( Commit is signed off (DCO) as |
main does not compile: BUILTIN_CLASSES references UriBuiltins, which lives in the impls subpackage and so needs an explicit import. #156 branched before #171 replaced the wildcard impls import with explicit ones, so adding UriBuiltins.class compiled on that branch. The two merged without a textual conflict, leaving the reference with no import. Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
The OKP branch added in 4fb00ae compiled on this branch's base, where TokenBuiltins used a wildcard `com.nimbusds.jose.jwk.*` import. Main has since expanded that wildcard (c75bba7, open-policy-agent#171) into explicit imports that do not cover Curve or OctetKeyPair, so the merge builds cleanly in git but fails javac. Add the two imports. The compliance ratchet added on main also needs io.jwt.verify_eddsa removed from known-missing-builtins.txt, since the builtin now resolves and the suite fails on stale entries. Squash before merge. Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
* Implement io.jwt.verify_eddsa builtin (closes #145) Signed-off-by: Muhammad Umer Hammad <umerhammad010@gmail.com> * Address review: support Ed25519 (OKP) JWKs in extractPublicKey Signed-off-by: Muhammad Umer Hammad <umerhammad010@gmail.com> * Fixup into 4fb00ae: import Curve/OctetKeyPair, drop ratchet entry The OKP branch added in 4fb00ae compiled on this branch's base, where TokenBuiltins used a wildcard `com.nimbusds.jose.jwk.*` import. Main has since expanded that wildcard (c75bba7, #171) into explicit imports that do not cover Curve or OctetKeyPair, so the merge builds cleanly in git but fails javac. Add the two imports. The compliance ratchet added on main also needs io.jwt.verify_eddsa removed from known-missing-builtins.txt, since the builtin now resolves and the suite fails on stale entries. Squash before merge. Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com> --------- Signed-off-by: Muhammad Umer Hammad <umerhammad010@gmail.com> Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com> Co-authored-by: Sebastian Spaink <sebastianspaink@gmail.com>
Closes #90
Summary
Mechanically expands all
import x.y.*;wildcard imports to explicitimports (51 wildcard import lines across 35 files).
Per the issue's own stated resolution, two static wildcard imports are
kept as-is (idiomatic JUnit/Mockito style) and are now excluded from
AvoidStarImportviaconfig/checkstyle/checkstyle.xml, so the checkreflects the intended scope going forward instead of silently ignoring
them:
org.junit.jupiter.api.Assertions.*(22 sites)org.mockito.Mockito.*(6 sites)org.mockito.ArgumentMatchers.*andjava.lang.Math.*were notcalled out in the issue as exceptions, so those were expanded like
everything else.
One dead wildcard import (
io.github.open_policy_agent.opa.ast.builtin.impls.*in
CapabilitiesGenerator.java) was simply unused and removed ratherthan expanded.
No reordering of unrelated imports, no reformatting of unrelated code
— only import lines and the one checkstyle config change.
Test plan
./gradlew compileJava compileTestJava—BUILD SUCCESSFUL./gradlew checkstyleMain checkstyleTest— 0AvoidStarImport/UnusedImports/RedundantImportviolations (was 79AvoidStarImportviolations before). Total checkstyle warningcount: 514 (main) → 435 (branch), exactly the 79 removed
star-import warnings, confirming no other checkstyle regressions.
./gradlew build—BUILD SUCCESSFUL(full build incl. tests, PMD)