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

Fix Controller.shouldBeCheckedForEnhancement method #1272

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dcrall
Copy link

@dcrall dcrall commented Sep 27, 2018

Rename the method Controller.shouldBeCheckedForEnhancement to Controller.enhancementCheckComplete to accurately reflect what the code is doing. Addresses issue #1271.

Rename the method Controller.shouldBeCheckedForEnhancement to
Controller.enhancementCheckComplete to accurately reflect what
the code is doing.
@asolntsev asolntsev self-assigned this Sep 29, 2018
@asolntsev
Copy link
Contributor

@dcrall I agree that current name shouldBeCheckedForEnhancement is incorrect. It should be the opposite: shouldNotBeCheckedForEnhancement. But your proposed name enhancementCheckComplete doesn't seem to be clear for me. Why "check is complete"? At that moment, enhancement check is not even started yet.

@dcrall
Copy link
Author

dcrall commented Sep 29, 2018

@asolntsev Thank you for reviewing the change. When the condition in this method is true, we actually return from the method, so the enhancement check is complete. We check for enhancements while we see application code. As soon as we're back in framework code, we know all application code is enhanced and the enhancement check is complete. I believe my method name is correct.

@asolntsev
Copy link
Contributor

@dcrall You are talking about the code that calls method shouldBeCheckedForEnhancement, not abut this method itself. Any method's name should reflect what it does, not how it's used by someone else.

If method does FOO, it should be named FOO, no matter if it's used for BAR or BAR2 or whatever else.

@dcrall
Copy link
Author

dcrall commented Sep 30, 2018

@asolntsev If your argument is that the method should describe what it is mechanically checking, then the name should be something like isFrameworkClass. However, I believe the "what" is that we are looking to see if our enhancement check is complete. The "how" is that we have re-entered framework code in the stack trace.

Additionally, this is not a general purpose method. This is a method that was extracted to provide clarity in the calling code. It is hard to see how it will be used in any other context. Regardless, the method has nothing to do with if that class should be checked for enhancement.

I think if we want to focus on the enhancement check, which makes sense. I would suggest something like this:

if (haveSeenFirstApplicationClass) {
    if(!isFrameworkClass(className)) {
        // check for enhancement
    } else {
        return; //enchancement check complete
    }
}

This structure complements the haveSeenFirstApplicationClass flag and makes the exit check secondary to the primary work of the method. I would be happy to make this change if you think it better.

Modified names to mark the entrance into and out of application code
to better highlight when we need to verify a class on the stack needs
to be enhanced.

Extract method for checking if a class is enhanced to not muddy the
structure of iterating over the stack.
@asolntsev
Copy link
Contributor

@dcrall No, isFrameworkClass is not a proper name because jdk.* and sun.* are not part of Play framework.

I agree, this is not a general-purpose method, and it's not intended to be used from outside.
But still, this design principal is general, independent from method scope: method name should reflect what id does.

I don't think it should be paired with haveSeenFirstApplicationClass, I think it should be paired with ContinuationEnhancer.isEnhanced(className). Because depending on the result of our method we decide if we should call isEnhanced. So, it seems reasonable flow to me:

if (should be check for enhancement) {
  <check for enhancement>
}

- Renamed isFrameworkClass() to isFrameworkCode(). The check for framework code
includes JDK classes. We see these in the stack as the Play framework is reflectively
invoking application code.

- Pulled the guard clause that detects that we are no longer examing application code
away from the enhancement check to highlight that it is not merely checking if the
current class should be enhanced but instead signalling the entire verification is
complete and that we should exit the method.
@dcrall
Copy link
Author

dcrall commented Oct 1, 2018

@asolntsev - Okay, this is my last attempt. If you don't like this, go ahead and change the name to shouldNotBeCheckedForEnhancement() and be done with it.

My change is really two fold at this point. One, I changed haveSeenFirstApplicationClass to verificationStarted. This marks the first boundary where we start ensuring that the current class is enhanced.

Two, I pulled the second boundary check into its own if clause to make it clear that it is detecting when we are done with application code and the verification check as a whole. I think having it in the if/else with the enhancement check did not make it clear that we were not just examining the current class.

In the end, I settled on shouldNotBeEnhanced() as the contested method name, which is pretty close to where we started. I hope that addresses your concern, and I think it works well with the verificationStarted flag.

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.

2 participants