jenkinsci / jenkinsci/lib-access-modifier
Restrictions do not apply to class literals, `instanceof`, casts, or method references
- Dominant language
- Java
- Stars
- 20
- Forks
- 20
- Avg merge
- 4h 9m
- Merged PRs (30d)
- 1
Description
I am not sure if this is intended, but restrictions do not apply to class literals (`XYZ.class`) (EDIT: and a few other cases, see https://github.com/jenkinsci/lib-access-modifier/issues/166#issuecomment-1686950515). For example, `access-modifier-checker` does not fail given this in one module:
```
@Restricted(NoExternalUse.class)
class Foo { }
```
And this in another module:
```
class Bar {
Bar() {
Foo.class.getName();
}
}
```
I think it is straightforward to fix this if we do consider it a bug by expanding `Checker.RestrictedMethodVisitor` to override `visitLdcInsn`, although I would not be surprised if plugins are inadvertently relying on the current behavior, making this a source-incompatible change.
Contributor guide
Research direction
Start by inspecting Checker.RestrictedMethodVisitor and how access-modifier-checker handles class literals, instanceof, casts, and method references. Review the linked issue discussion for the additional cases and assess the source-compatibility concern. Done means restrictions are enforced consistently for the reported usages, with coverage for the affected bytecode visits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100