gnodet commented on code in PR #1983:
URL: https://github.com/apache/maven-resolver/pull/1983#discussion_r3645619293
##########
maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java:
##########
@@ -153,43 +152,85 @@ private boolean doRun(DocletEnvironment environment) {
continue;
}
DocCommentTree docComment = docTrees.getDocCommentTree(field);
- if ("maven".equals(mode)) {
- processMavenField(type, field, docComment, discoveredKeys);
- } else if ("resolver".equals(mode)) {
- processResolverField(type, field, docComment,
discoveredKeys);
- } else {
- throw new IllegalArgumentException("Unknown mode: " +
mode);
+ try {
+ if ("maven".equals(mode)) {
+ processMavenField(type, field, docComment,
discoveredKeys);
+ } else if ("resolver".equals(mode)) {
+ processResolverField(type, field, docComment,
discoveredKeys);
+ } else {
+ // TODO: move to beginning of run() and validate mode
before processing any types
+ reportError("Unknown mode: " + mode);
+ return false;
+ }
+ } catch (DocTreePathAwareRuntimeException e) {
+ reportError(e.getDocTreePath(), e.getMessage());
+ } catch (RuntimeException e) {
+ DocTreePath rootPath = new
DocTreePath(docTrees.getPath(field), docComment);
+ reportError(rootPath, e.getMessage());
Review Comment:
Low-severity: The `DocTreePath` constructor calls `Objects.requireNonNull`
on the `DocCommentTree` parameter, so if `docComment` is null when a
`RuntimeException` is caught here, the catch block itself would NPE and mask
the original error.
In resolver mode this is unreachable (early return on null `docComment`),
but `processMavenField` does not guard against null `docComment` in the same
way. Interestingly, `buildTagPath` (line 355–361 in this PR) already applies
exactly this defensive pattern.
```suggestion
} catch (RuntimeException e) {
DocTreePath rootPath =
docComment != null ? new
DocTreePath(docTrees.getPath(field), docComment) : null;
reportError(rootPath, e.getMessage());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]