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

Always reject the #getClass() method #154

Merged
merged 2 commits into from
Apr 8, 2019

Conversation

daniel-beck
Copy link
Member

There seems to be no legitimate use case for allowing #getClass() to be called, and not allowing it will make the following statement true:

It's a fundamental property in Stapler's use of naming convention for its routing, and carefully written applications can just not expose public fields or methods matching the conventional getWhatever name on objects they make reachable through routing unless they're intended to be routed, and thereby sidestep the problem.

#153 (comment) has a more limited variant of that, and there's no reason it should not be true.

Untested.

@Wadeck

@@ -182,7 +182,7 @@ public String toString() {
});
}

FunctionList getMethods = node.methods.prefix("get");
FunctionList getMethods = node.methods.prefix("get").filter(m -> !m.getSignature().equals("method getClass"));
Copy link
Member Author

Choose a reason for hiding this comment

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

method java.lang.Object getClass actually.

So it looks like this deserves a test after all.

Copy link
Contributor

@Wadeck Wadeck left a comment

Choose a reason for hiding this comment

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

👍 for the idea
🐝 🍺 with test ;)

Assert.assertFalse(metaClass.dispatchers.stream().filter(d -> d instanceof NameBasedDispatcher).anyMatch(d -> ((NameBasedDispatcher) d).name.equals("class")));

// in fact, there should be no name based dispatchers at all
Assert.assertFalse(metaClass.dispatchers.stream().anyMatch(d -> d instanceof NameBasedDispatcher));
Copy link
Member

Choose a reason for hiding this comment

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

Could just drop the first assertion in that case?

Copy link
Member Author

Choose a reason for hiding this comment

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

The redundancy here captures the intent better IMO.

@jglick
Copy link
Member

jglick commented Dec 14, 2018

merge with master to get CI

@daniel-beck
Copy link
Member Author

merge with master to get CI

Improved the code instead 🤓

@jglick jglick merged commit 0376589 into jenkinsci:master Apr 8, 2019
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