-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
CLOUDSTACK-9796 - Fix NPE in VirtualMachineManagerImpl.java #1956
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can " work.getStep()" return null?
I see that you add a check at line 757
previousStep != null
. Why would we need that check there, and not need it here (line750)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelweingartner if work is null, previousStep will stay null. Maybe not the clearest way to handle this, but this prevents a null work from being passed down below. In other words, if work is null, previousStep will be guaranteed null, and if previousStep is not null, then work is guaranteed to be not null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, now I think I am starting to get it.
But I am still not sure about some things here, would you mind continue discussing?
If the work is not null, you get the previous step (let’s assume it is not null) and call the method
_workDao.updateStep(work, step)
. After this, you callstateTransitTo(vm, event, hostId)
. Why do we need to call_workDao.updateStep(work, previousStep)
again at line 758 that is executed when the method finishes? ThepreviousStep
continues to be the same.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this code I didn't write, but I can make some guesses:
_workDao.updateStep(work, previousStep) line is in the finally block, which will execute even if an exception is thrown in stateTransitTo (like NoTransitException for instance). So if stateTransitTo a) returns a false, or b) throw an exception, then result will be false, and line 758 will run. So if something happens that the state isn't transitioned, someone wanted the work reverted to its previous step value. Sort of a rollback maybe?
In the case of the VM hung in starting, my desired side effect is I want stateTransitTo to be called and set the state to Stopped , i.e., Event.AgentReportStopped -> State.Stopped . The work has already expired at this point, so it is null. I was trying to preserve the same behavior as before when work was not null.
Sorry if this wasn't very clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and to your point earlier, getStep() generally shouldn't ever return a null I don't think , because the step column in the op_it_work table is marked not null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not asking to make a distinction between exception or not. What I tried to say is that, if the intent/purpose of the
finally
block was only to revert the step to a previous state when exceptions occur, we could do that using acatch
block. I think the finally here is meant to revert the state of work step even if an exception does not happen, for instance whenstateTransitTo
returnsfalse
.I think you already answered my doubt; when you said that the
previousStep
is most likely never to benull
. I thought we could have cases wherepreviousStep == null
, and then if thestateTransitTo
returns false, with the newly added check at line 757, we would not update the step back tonull
for these cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think something like:
would be better? Even if work.getStep() did return a null, that should have the same effect as before. Maybe it would be more readable too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think this is more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks for the input
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thank you