wkschwartz
wkschwartz

Reputation: 3877

Java compiler overwriting and mangling source file

I have a single, short Java file with a single main method. It imports from a third-party library that I'll call thirdpartylib. I run

javac -classpath "../thirdpartylib/lib/*" MyClass.java

at the command line. I get the following command-line output:

warning: Supported source version 'RELEASE_6' from annotation processor 'org.mangosdk.spi.processor.SpiProcessor' less than -source '1.8'
MyClass.java:14: error: unreported exception Exception; must be caught or declared to be thrown
d.put(125,   new HashSet<>(Arrays.asList(0, 1, 2)));
                         ^
  exception thrown from implicit call to close() on resource variable 'facade'
MyClass.java:39: error: unreported exception Exception; must be caught or declared to be thrown
2 errors
1 warning

Then when I open MyClass.java back up in my editor to investigate the reported errors, my Java file has been completely rewritten! (My editor's undo history saved me.) The top of the file reads

# Generated by org.mangosdk.spi.processor.SpiProcessor (0.2.4)
# Mon, 18 Jul 2016 10:10:47 -0500

and the rest of my code looks like it was sorted row-wise in alphabetical order -- not valid Java syntax to say the least. Googling around got me to an apparently defunct package called SPI. I have not installed it on my computer, except perhaps if thirdpartylib is using it, but that doesn't explain why it's destroying my source code.

How can I compile my program if the compiler keeps deleting my source code?

Upvotes: 3

Views: 288

Answers (1)

kapex
kapex

Reputation: 29999

It looks like the classpath contains an annotation processor. Annotation processors should usually only generate new resources and not modify existing ones, but they do have the ability to change any files.

You can try to use the compiler option -proc:none to disable all annotation processing.

javac -proc:none -classpath "../thirdpartylib/lib/*" MyClass.java

Upvotes: 3

Related Questions