jenkinsci / jenkinsci/lib-access-modifier

Restrictions do not apply to class literals, `instanceof`, casts, or method references

Open
#166 6 comments 0 reactions 0 assignees View on GitHub
bug
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.