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

prevent nullpointer in SafeParametersAction #222

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tfs/src/main/java/hudson/plugins/tfs/SafeParametersAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ public SafeParametersAction(final ParameterValue... parameters) {
this(Arrays.asList(parameters));
}

/**
* Will be called when the object is unmarshalled. Because the normal
* constructors are not called in such a case, things may not be initialized
* correctly. This will check that ParametersAction.parameters is not null
* @return Correctly initialized SafeParametersAction
*/
protected Object readResolve() {
try {
// if ParametersAction is not a null everything is ok
if (super.getParameters() != null) {
return this;
}
} catch (NullPointerException npe) {
}

// Either super.getParameters was null or threw a NPE
// so create a new SafeParametersAction that initializes
// everything correctly. This should rarely happen
return new SafeParametersAction(this.getParameters());
}

@Override
public List<ParameterValue> getParameters() {
return Collections.unmodifiableList(parameters);
Expand Down