Skip to content
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

Ignore issue when coming from the same class #6

Closed
wants to merge 1 commit into from

Conversation

batmat
Copy link
Member

@batmat batmat commented May 19, 2017

Trying to fix jenkinsci/jenkins#2892 I got blocked because DoNotUse would fail apparently on TimeUnit2 enum instances. This fixes this behaviour and ignores issues when an usage is from the same class. (for instance, it's OK for a class marked DoNotUse to leave it as is, that it calls itself)

@batmat
Copy link
Member Author

batmat commented May 20, 2017

@reviewbybees for more eyes on this, even if done on personal time.

@batmat
Copy link
Member Author

batmat commented May 20, 2017

Ping @kohsuke as this will be required to merge Jenkins' jenkinsci/jenkins#2892 (if deemed correct).

@ghost
Copy link

ghost commented May 20, 2017

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@@ -35,26 +35,44 @@
*/
public class DoNotUse extends AccessRestriction {
public void written(Location loc, RestrictedElement target, ErrorListener errorListener) {
if (target.isSameClass(loc)) {
return;
}
error(loc,target,errorListener);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe factor into a private helper method.

public boolean isSameClass(Location location) {
String locationClassName = location.getClassName();
if (locationClassName.contains("$")) {
locationClassName = locationClassName.split("\\$")[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

String locationClassName = location.getClassName().replaceFirst("[$].+$", "");

if (locationClassName.contains("$")) {
locationClassName = locationClassName.split("\\$")[0];
}
if(keyToClassName(keyName).equals(locationClassName)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to work with all cases of nested classes? Like

class Outer
  @Restricted(DoNotUse.class)
  static class Middle {
    static class Inner {
      static {new Middle();}
    }
  }
}

?


import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I do not trust mocks and would recommend a new IT.

@oleg-nenashev
Copy link
Member

@batmat any plans to finalize it?

@batmat
Copy link
Member Author

batmat commented Sep 17, 2017

Finally simplified the upstream PR to use NoExternalUse instead of DoNotUse. I'm missing time to finalize this and preferred the "easy" way to move forward.

(Sorry Oleg, had missed that ping above :-()

@batmat batmat closed this Sep 17, 2017
@batmat batmat deleted the fix-self-ref-issue branch September 17, 2017 13:42
batmat added a commit to batmat/github-branch-source-plugin that referenced this pull request Jan 22, 2019
until jenkinsci/lib-access-modifier#6 is revived, if
ever.

LOL, @jglick was the one reminding me about that PR 🤦 :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants