@@ -506,20 +506,21 @@ protected final A myself() {
506506 */
507507 protected List <String > buildFlags (JctFlagBuilder flagBuilder ) {
508508 return flagBuilder
509- .annotationProcessorOptions (getAnnotationProcessorOptions () )
510- .showDeprecationWarnings (isShowDeprecationWarnings () )
511- .failOnWarnings (isFailOnWarnings () )
512- .compilerOptions (getCompilerOptions () )
513- .previewFeatures (isPreviewFeatures () )
514- .release (getRelease () )
515- .source (getSource () )
516- .target (getTarget () )
517- .verbose (isVerbose () )
518- .showWarnings (isShowWarnings () )
509+ .annotationProcessorOptions (annotationProcessorOptions )
510+ .showDeprecationWarnings (showDeprecationWarnings )
511+ .failOnWarnings (failOnWarnings )
512+ .compilerOptions (compilerOptions )
513+ .previewFeatures (previewFeatures )
514+ .release (release )
515+ .source (source )
516+ .target (target )
517+ .verbose (verbose )
518+ .showWarnings (showWarnings )
519519 .build ();
520520 }
521521
522- @ SuppressWarnings ("NullableProblems" ) // https://youtrack.jetbrains.com/issue/IDEA-311124
522+ @ SuppressWarnings ({"NullableProblems" , "ThrowFromFinallyBlock" })
523+ // NullableProblems is needed due to https://youtrack.jetbrains.com/issue/IDEA-311124
523524 private JctCompilation compileInternal (
524525 @ WillNotClose Workspace workspace ,
525526 @ Nullable Collection <String > classNames
@@ -528,13 +529,27 @@ private JctCompilation compileInternal(
528529 var flagBuilderFactory = getFlagBuilderFactory ();
529530 var compilerFactory = getCompilerFactory ();
530531 var compilationFactory = getCompilationFactory ();
532+ var flags = buildFlags (flagBuilderFactory .createFlagBuilder ());
533+ var compiler = compilerFactory .createCompiler ();
534+ var fileManager = fileManagerFactory .createFileManager (workspace );
531535
532- try (var fileManager = fileManagerFactory .createFileManager (workspace )) {
533- var flags = buildFlags (flagBuilderFactory .createFlagBuilder ());
534- var compiler = compilerFactory .createCompiler ();
536+ // Any internal exceptions should be rethrown as a JctCompilerException by the
537+ // compilation factory, so there is nothing else to worry about here.
538+ // Likewise, do not catch IOException on the compilation process, as it may hide
539+ // bugs. Hence, we have to use a try-finally-try-catch-rethrow manually rather than a nice
540+ // try-with-resources. This is kinda crap code, but it prevents reporting errors incorrectly.
541+
542+ try {
535543 return compilationFactory .createCompilation (flags , fileManager , compiler , classNames );
536- } catch (IOException ex ) {
537- throw new JctCompilerException ("Failed to close file manager" , ex );
544+ } finally {
545+ try {
546+ fileManager .close ();
547+ } catch (IOException ex ) {
548+ throw new JctCompilerException (
549+ "Failed to close file manager. This is probably a bug, so please report it." ,
550+ ex
551+ );
552+ }
538553 }
539554 }
540555}
0 commit comments