Why idea can compile at a language level higher than the SDK level for JDK9 (or later) but report invalid Source release for JDK8 (or lower)

Answered

but when I change the module SDK to jdk8, the idea throws the error "invalid source release"!

When I set the module SDK to jdk8(jdk7, jdk6), and also set the module language level to 11, the result is the idea throws "invalid source release". But, when I just change the module SDK to jdk9(jdk10), the module language level is still 11, the idea could make a normal compilation

At first, I thought the language level was higher than the SDK level anWd would not compile properly, but Jdk9 and above versions can indeed compile at a higher language level than the module version like module SDK 9 with language level 14

7 comments
Comment actions Permalink

Hello!

I've got the same error with JDK 9 as well. Could you please attach screenshot from "Settings | Build, Execution, Deployment | Compiler | Java Compiler"?

0
Comment actions Permalink

Yaroslav Bedrov I would like to ask if IDEA projects can only be compiled at the language level which is lower than the SDK version under normal circumstances. Is that right? In fact, when I set the module SDK to JDK9(or later), the language level will compile normally regardless of the higher or lower SDK version

1
Comment actions Permalink

@Yaroslav Bedrov  There doesn't seem to be a benchmark. Because in terms of actual performance, when you set module SDK to JDK8(or lower versions), the project can be compiled only in this way of setting the language level to less than 8. But when you set module SDK to JDK9(or higher versions), the project can be compiled whether the language level is set to less than 9 or not. There seems to be a watershed between JDK 8 and JDK9

 

 

 

1
Comment actions Permalink

Not exactly. I've got the same message with project SDK set to 11 and language level to 14/15. Please try to clean modules bytecode version in "Settings | Build, Execution, Deployment | Compiler | Java Compiler".

0
Comment actions Permalink

Yaroslav Bedrov By the way, my module bytecode version is always under the module SDK level for all tests!

when module SDK set to 11 and language level to 14/15 and set the module bytecode version to 11 which is the same as the SDK level, you'll find that idea throws "invalid source release"!

But, when you just change the module bytecode version to 10(As long as it's below 11), things will be different!

The two settings above have the normal compilation without any error

1
Comment actions Permalink

Yaroslav Bedrov I am not sure if it's a bug for IDEA In version compatibility!

1
Comment actions Permalink

Please try to disable "Use --release option..." in "Settings | Build, Execution, Deployment | Compiler | Java Compiler". Then IDE should show error with 8/10 bytecode versions as well.

0

Please sign in to leave a comment.