[RFC] [POC] - report missing classes#1371
Conversation
anywhere. API is ugly and needs to be defined yet. The problem should be reported as a configuration error rather than a processing error. But a configuration error needs a rule and is unfortunately currently ignored by the maven-pmd-plugin... (it doesn't end up in the report). But in general, it works - the missing classes end up as processing errors in the final report. I probably missed some cases where we should report missing classes or reporting the cases multiple times... In the end, we should probably deduplicate and report each missing class only once.
There was a problem hiding this comment.
we do want to report on NoClassDefFoundError, but do we want to do so on other LinkageError such as ClassFormatError (#1330 / #1131)? I'm unsure an end user would be able to understand and fix those scenarios on it's own
Also, I'd consider reporting this separately and not just as a ProcessingError... I think reporting "The class foo.bar.Baz is missing from auxclasspath, this report could be incomplete" or something of the sort, instead of a stacktrace. It should be much friendlier to the user. Maybe a ConfigurationError error is easier on this as it takes a String and not an exception?
Also, we should filter out duplicates from this report...
|
Maybe, instead of relying on static state (and the initialization/reset that requires) we could pass around a special error logger in the AstAnalysisConfiguration I introduce in #1426. This is what the object's made for, and it would be in scope at the current call sites of your ThreadContextHolder. I agree with @jsotuyod that the error reporting should be user-friendly, though I guess that can be handled by the report renderers? Maybe using a subclass of ProcessingError would allow us to filter them out at that point? In the less verbose report formats, we could also only display the package names when there are very many missing classes. |
|
I've come back to this after some time… I don't think passing around
Moving the I think we should aim for the following: Have a new
It could provide a simple method such as After analysis, we can dump these into the Notice, another benefit of this approach is that introduces no breaking API changes, so we can do it on master at any time. |
|
@jsotuyod I don't really like that approach.
TBH I think we should add a If we do that then the analysis context is not specific to a file anymore, and it's basically your AnalysisContext
I don't think we should base any work on this hypothesis. If we have a richer data model for symbol/type resolution, that rule doesn't need to process Class objects. Same thing for eg UnnecessaryFullyQualifiedName and such. I'd rather shift the responsibility of processing Class objects away from rules, because that will simplify them, and allow sharing insight between all rules. I've already written about that extensively in #1566 and in our meeting briefs so won't go back into that.
This is irrelevant. Making it lazy doesn't mean we can't use a context object. We could have a lazy type resolver object per compilation unit, created with a context object.
I think passing around a special logger object would be more general and scale better. Eg with methods like In general I think "more threadlocals" shouldn't ever be a long term design, precisely because we don't know exactly how PMD is executed outside of our codebase. It makes data ownership obscure, makes the app harder to understand. Reifying global things into context objects and passing them around is a much better place to start from I think. There are not many places where the parameter passing is needed, and nearly all of them are in the internals of PMD, which is internal API. |
|
Closing this without merging it. It is irrelevant, will be replaced by a solution for #3914. |
This adds a PmdThreadContextHolder to have access to the report anywhere.
API is ugly and needs to be defined yet. The problem should be reported
as a configuration error rather than a processing error. But a
configuration error needs a rule and is unfortunately currently
ignored by the maven-pmd-plugin... (it doesn't end up in the report).
But in general, it works - the missing classes end up as processing
errors in the final report.
I probably missed some cases where we should report missing classes
or reporting the cases multiple times...
In the end, we should probably deduplicate and report each missing
class only once.
This would be part of #194