2

I have a project with many modules, all of which need to be compiled using Java 7. I have made sure every setting that I know of to point to that version of Java, yet somehow, every time I rebuild the project I get:

Information:javac 11.0.3 was used to compile java sources

followed by a list of errors:

Warning:(86, 25) java: as of release 9, '_' is a keyword, and may not be used as an identifier

Error:(86, 25) java: cannot find symbol
  symbol:   class _
  location: class com.(...)`

Following other questions like:

Can't resolve -source errors on IntelliJ with regards to Project Language Level

IntelliJ IDEA tells me "Error:java: Compilation failed: internal java compiler error idea"

I have tried these settings:

  • Under Project Structure -> Project -> Project SDK: 1.7
  • Project Structure -> Project language level -> 7 - Diamonds, ARM, multi-catch etc.
  • Under Project Structure -> Modules checked every module, and that was not fun, because there are about 50. Sources tab -> Language level: Project detaulf (7 - Diamonds, ARM, multi-catch etc.)
  • Project Structure -> Modules, each Dependencies tab -> Module SDK: Project SDK (1.7)
  • Project Structure -> SDKs: it listed IDEA's built in Java 11, so I removed it, leaving only: 1.7
  • Settings -> Java Compiler -> Use compiler: Javac
  • Settings -> Java Compiler -> Use compiler from module target JDK when possible: unticked
  • Settings -> Java Compiler -> Per-module bytecode version: all modules set to 1.7

I am running the latest version of IntelliJ IDEA:

IntelliJ IDEA 2019.2 (Ultimate Edition) Build #IU-192.5728.98, built on July 23, 2019

Is this a bug with IDEA?

kter
  • 33
  • 1
  • 3
  • 5
    Wait, you have a class named `_`? – Thomas Aug 14 '19 at 07:51
  • @Thomas looking at it, it points to a line `@Getter(onMethod = @__(@JSONProperty(ignoreIfNull = true)))` it's the `_` after the @ disclaimer: I did not write this code, I don't know what that line does :) – kter Aug 14 '19 at 07:58
  • Have you tried to `Switch the boot JDK` ? – Arnaud Claudel Aug 14 '19 at 08:12
  • @ArnaudClaudel could you provide a bit more background? I'm not sure what that means – kter Aug 14 '19 at 08:15
  • It changes the runtime of IntelliJ, maybe it used by default for compilation. [Source](https://www.jetbrains.com/help/idea/switching-boot-jdk.html) – Arnaud Claudel Aug 14 '19 at 08:22
  • Are you using a build system such as Gradle or Maven? Is that configured for jdk1.7 too? What happens if you just type `gradle build` on the command line? – DodgyCodeException Aug 14 '19 at 08:43
  • @DodgyCodeException we have maven, I think the equivalent would be using `mvn compile`, and that finishes with a BUILD SUCCESS. Not sure where you specify JDK in pom though, but running the script through IDE logged out that it executed with the correct default JDK – kter Aug 14 '19 at 09:13

2 Answers2

3

Here is the reason Intellij is choosing java 11: https://www.jetbrains.com/help/idea/configuring-build-jdk.html

IntelliJ IDEA checks all JDKs that are used in the project: the JDKs that are defined on both the project and module levels.

IntelliJ IDEA calculates the latest of these JDKs. This is necessary to make sure that all modules can be compiled.

If the version of the latest JDK configured is lower than 1.6, IntelliJ IDEA will pick the JDK version that is used for running the IDE. This limitation is related to the fact that the compiler API used by IntelliJ IDEA for building projects is supported starting from JDK 1.6.

And that is why switching the boot JDK to JDK8 re-enables the compilation of older java classes.

  • Ok, but the project's version that I mention in my question relies on JDK 1.7, so it shouldn't do that according to this – kter Jan 10 '20 at 15:46
  • You are right, I had a similar problem but with a module still using JDK 1.4. In your case it should work since no JDK lower than 1.6 is configured. So maybe this is a bug in Intellij-IDEA? – Zigo Webdesign Jan 13 '20 at 14:54
  • This bug might be related: https://youtrack.jetbrains.com/issue/IDEA-209978 – Zigo Webdesign Jan 13 '20 at 15:02
0

As mentioned in the comments by @Arnaud Claudel, I have tried switching the boot JDK of IDEA (described here https://www.jetbrains.com/help/idea/switching-boot-jdk.html) which helped. Incidentally, the lowest JDK version that IDEA will accept is 8.

I am not sure it is actual solution though and not just a workaround, because why would the IDE use JDK 11 in the first place, ignoring all the project's settings. So I am leaving this question open for anyone to post a better solution.

kter
  • 33
  • 1
  • 3
  • I think this can be an actual solution because support matrix for IntelliJ is determined by Jet Brains. Minimum JDK accepted for that version could be 8. I assure you, there is almost no chance of coming up with a better solution. – Kavitha Karunakaran Aug 14 '19 at 10:05
  • 1
    Are you suggesting Jet Brains is dropping support for JDK7 projects within IntelliJ? Because I don't think that's what's happening. – kter Aug 14 '19 at 10:21
  • Actually Java 7 itself has reached end of public update and support from Oracle. Oracle suggested existing Java 7 customers to migrate to later versions as early as April 2015. https://java.com/en/download/faq/java_7.xml – Kavitha Karunakaran Aug 14 '19 at 10:28
  • In such a scenario, you cannot expect IDEs to support all versions although the language supports backward compatibility – Kavitha Karunakaran Aug 14 '19 at 10:30