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

Rework EnvironmentContext#getSubject method to not return null subject #3813

Merged
merged 1 commit into from
Jan 23, 2017

Conversation

sleshchenko
Copy link
Member

@sleshchenko sleshchenko commented Jan 19, 2017

What does this PR do?

Rework EnvironmentContext#getSubject method to not return null subject. It allows to avoid null pointer exceptions in case missing component which should set subject for request in custom packaging.

What issues does this PR fix or reference?

Previous behavior

(Remove this section if not relevant)

New behavior

(Explain the PR as it should appear in the release notes)

Please review Che's Contributing Guide for best practices.

Tests written?

No

Docs updated?

Please add a matching PR to the docs repo and link that PR to this issue. Both will be merged at the same time.

Changelog

Rework EnvironmentContext#getSubject method to not return null subject

@codenvy-ci
Copy link

@skabashnyuk skabashnyuk added this to the 5.2.0 milestone Jan 20, 2017
@sleshchenko sleshchenko force-pushed the anonymousSubject branch 2 times, most recently from b8639d5 to cd0fb09 Compare January 20, 2017 07:59
@codenvy-ci
Copy link

@@ -799,7 +799,7 @@ private Subject sessionUser() {

private String sessionUserNameOr(String nameIfNoUser) {
final Subject subject;
if (EnvironmentContext.getCurrent() != null && (subject = EnvironmentContext.getCurrent().getSubject()) != null) {
if ((subject = EnvironmentContext.getCurrent().getSubject()) != Subject.ANONYMOUS) {
Copy link
Contributor

@benoitf benoitf Jan 20, 2017

Choose a reason for hiding this comment

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

shouldn't we use !EnvironmentContext.getCurrent().getSubject().equals(Subject.ANONYMOUS) instead of != ?
(I agree that it's testing for now the memory pointer but it may have side effect in future as I don't see tests)

Copy link
Member Author

@sleshchenko sleshchenko Jan 20, 2017

Choose a reason for hiding this comment

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

@benoitf
When can comparing by == work incorrect? Looks like only in case changing Subject from interface to class and making this field non final and setting some values.... I can't give the full variant :)
Equals can works incorrect if we change anonymous implementation to SubjectImpl("0000-000-00", "Anonynous", null, false) then equals won't show that it is really anonymous that are returned by EnvironmentContext, or it is some Subject with id "0000-000-00" and name "Anonynous". (I agree that it is crazy example)
Do you think that using equals there is correct variant?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@benoitf So this method is used only for logging. I don't know any way to test it and I think we can miss it(Mb you know?). Also we could make this method package private and test only its functionality, but I don't like this way in this case. Because it will be more testing of EnvironmentContext#getSubject method than sessionUserNameOr functionality :)
Mb the best way is adding isAnonymous() method to Subject and don't use subject comparing in such use cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes I was thinking the same on having isAnonymous() so it delegates the test to Subject and not to all callers

Copy link
Member Author

@sleshchenko sleshchenko Jan 23, 2017

Choose a reason for hiding this comment

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

@benoitf Please, review my new changes

Copy link
Contributor

Choose a reason for hiding this comment

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

@sleshchenko looks perfect for me

@sleshchenko sleshchenko force-pushed the anonymousSubject branch 2 times, most recently from 70dedd8 to 93ef1bf Compare January 23, 2017 14:58
@sleshchenko sleshchenko merged commit d49f732 into eclipse-che:master Jan 23, 2017
@sleshchenko sleshchenko deleted the anonymousSubject branch January 23, 2017 15:50
@codenvy-ci
Copy link

@JamesDrummond JamesDrummond mentioned this pull request Feb 6, 2017
9 tasks
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.

6 participants