-
Notifications
You must be signed in to change notification settings - Fork 674
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
SOLR-17119: Exception swallowing in ContainerPluginsApi causes some config validation errors to be ignored #2202
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,12 @@ | |
|
||
package org.apache.solr.handler.admin; | ||
|
||
import static org.apache.lucene.util.IOUtils.closeWhileHandlingException; | ||
|
||
import java.io.IOException; | ||
import java.lang.invoke.MethodHandles; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import org.apache.solr.api.AnnotatedApi; | ||
import org.apache.solr.api.ClusterPluginsSource; | ||
import org.apache.solr.api.Command; | ||
import org.apache.solr.api.ContainerPluginsRegistry; | ||
|
@@ -130,28 +127,24 @@ public void update(PayloadObj<PluginMeta> payload) throws IOException { | |
} | ||
|
||
private void validateConfig(PayloadObj<PluginMeta> payload, PluginMeta info) throws IOException { | ||
if (info.klass.indexOf(':') > 0) { | ||
if (info.version == null) { | ||
payload.addError("Using package. must provide a packageVersion"); | ||
return; | ||
} | ||
} | ||
List<String> errs = new ArrayList<>(); | ||
ContainerPluginsRegistry.ApiInfo apiInfo = | ||
coreContainer.getContainerPluginsRegistry().createInfo(payload.getDataMap(), errs); | ||
if (!errs.isEmpty()) { | ||
for (String err : errs) payload.addError(err); | ||
if (info.klass.indexOf(':') > 0 && info.version == null) { | ||
payload.addError("Using package. must provide a packageVersion"); | ||
return; | ||
} | ||
AnnotatedApi api = null; | ||
try { | ||
apiInfo.init(); | ||
} catch (Exception e) { | ||
log.error("Error instantiating plugin ", e); | ||
errs.add(e.getMessage()); | ||
return; | ||
} finally { | ||
closeWhileHandlingException(api); | ||
|
||
final List<String> errs = new ArrayList<>(); | ||
final ContainerPluginsRegistry.ApiInfo apiInfo = | ||
coreContainer.getContainerPluginsRegistry().createInfo(payload.getDataMap(), errs); | ||
|
||
if (errs.isEmpty()) { | ||
try { | ||
apiInfo.init(); | ||
} catch (Exception e) { | ||
log.error("Error instantiating plugin ", e); | ||
errs.add(e.getMessage()); | ||
} | ||
} | ||
|
||
errs.forEach(payload::addError); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't change the outcome, but maybe it could be done in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose to implement it this way so we are only adding errors in the response's payload ( We could however also do it as such, to keep the same flow as before my change if it improves readability : final List<String> errs = new ArrayList<>();
final ContainerPluginsRegistry.ApiInfo apiInfo =
coreContainer.getContainerPluginsRegistry().createInfo(payload.getDataMap(), errs);
if (errs.isEmpty()) {
try {
apiInfo.init();
} catch (Exception e) {
log.error("Error instantiating plugin ", e);
payload.addError(e.getMessage());
}
} else {
errs.forEach(payload::addError);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a side note, the way the I wanted to keep the changes from this pull request small enough to only remediate the identified bug, but I feel it would be worth refactoring as part of another pull request. In my opinion, we should just throw exceptions instead of relying on this errors' list (see ContainerPluginsRegistry.java#L329-L413), it would simplify the code and ease errors management when constructing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I didn't get it that only appending to |
||
} | ||
} |
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.
Is this method (missing in the modified version) what was causing the exception to be swallowed?
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.
The exception was swallowed here because the error message was mistakenly only added to the local
errs
list (line 151) but never included in the response's payload.The removal of the call to
closeWhileHandlingException(...)
is a minor code clean-up.In this context, the purpose of this method was to close the
AnnotatedApi
declared above (line 146), but as it is never instantiated this finally block always resulted in a no-op.I therefore removed both this unused local variable declaration and the finally block which was dedicated to closing this resource.