Comments (10)
If I understand correctly you tried to feed the extension source code which contained compilation errors. In that case, I think JavacExtension
will be more appropriate. See the javac extension.
Due to how ToolExtension
works internally, I don't think it's possible for it to parse uncompilable code.
from elementary.
It's just the annotation processor that throws errors, javac can parse if no problems.
To the very least, the error message shouldn't say "could not start the java compiler", that's just misleading: The Java compiler started, spat out error messages, terminated normally, and ToolsExtension
even constructs a Results
object.
from elementary.
But yeah I see what you mean; expecting javac to return an AST in case of errors, whether from an annotation processor or not, is likely going beyond what the TCK demands.
from elementary.
Could attach a short snippet of code that demonstrates this?
It seems strange that DaemonCompiler
includes an annotation processor when running. I think what may be happening is that DaemonCompiler
is unintentionally picking up the annotation processor on the classpath.
I can't think of how it might otherwise compile while including the annotation processor under test.
On another note, if an annotation processor does throw an exception, it does mean that compilation has failed since it is assumed that the annotation processor has errored out unintentionally. For expected errors, i.e. annotation processor expected some other type, it should log a failure using the given Messager instead.
from elementary.
Nah, it's the example project that's erroring out.
The compiler messages also have just the annotation processor's error message.
Example project is at https://github.com/toolforger/elementary-demo .
I put a breakpoint in DaemonCompiler.run()
, on the if (!results.success) {
line, so it was easy to check the logs and see what actually happened.
from elementary.
On a tangent, I think I can work around the issue with erroring-out annotation processor - just leave out the annotations, make the tests not check that the annotation processor errors out but just that the conditions hold that will make it error out, in those code snippets that we believe should trigger specific error conditions.
Still, the error message is misleading. I think it's this code that needs a bit of a rewrite:
try {
var results = compiler.compile(files);
if (!results.success) {
throw new CompilationException(results.find().diagnostics());
}
} catch (Throwable e) {
processor.environment.completeExceptionally(new CompilationException("Failed to start javac", e));
}
I think it should be something like this:
Results results;
try {
var results = compiler.compile(files);
} catch (Throwable e) {
processor.environment.completeExceptionally(new CompilationException("javac did not start, or crashed", e));
return;
}
if (!results.success) {
processor.environment.completeExceptionally(new CompilationException(results.find().diagnostics()));
}
This also avoids wrapping a CompilationException in another CompilationException, so the exception stack trace will have a better noise-to-signal ratio.
I wanted to insert a "javac completed with error messages:" line before the results.find().diagnostics()
messages, but it would have complicated the suggested code so I left it out for better clarity.
from elementary.
I think I get what you mean, but can't the if-statement be placed in the try-block? Also, any chance you would be willing to submit a PR for this on master heh?
EDIT: Okay I think I derped up here, the throw
should definitely be outside.
from elementary.
I have found over the years that nesting tends to couple code blocks, which can hinder refactoring. It also creates a bias towards keeping the code path joined, even if it shouldn't be.
The exact decision is pretty subjective though, so I don't care much about the exact flow.
The subjectivity is also why I didn't create a PR: I don't know what your priorities are, so any PR would probably be rejected and require more work from both of us.
from elementary.
Fair enough, I'll create a PR later then, thanks for reporting this issue regardless!
from elementary.
Fixed in b320fd0
from elementary.
Related Issues (14)
- Your .dependabot/config.yml contained invalid details HOT 1
- [BUG] Repo missing in elementary/README.md HOT 9
- [FEATURE REQUEST] Rename @Case to something better HOT 36
- [FEATURE REQUEST] First-class module support in JUnit extensions HOT 7
- [BUG] `MemoryFileManager ` does not handle modules correctly
- [FEATURE REQUEST] Better support for parameterized tests HOT 1
- [BUG] Modules don't compile HOT 1
- Deploy artifacts to maven central HOT 12
- Dependency Dashboard
- [FEATURE REQUEST] Auto-format pull requests
- [FEATURE REQUEST] Primitives for Module support HOT 7
- [BUG] com.karuslabs:satisfactory 1.1.3 is not available HOT 2
- Missing page "Why java 11?" HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elementary.