Bug 561239 - Multiple failures with Java 14 (JDK14) support
Summary: Multiple failures with Java 14 (JDK14) support
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.15   Edit
Hardware: PC Windows 10
: P3 major (vote)
Target Milestone: 4.19   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact: Sravan Kumar Lakkimsetti CLA
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2020-03-19 03:24 EDT by Paul Holder CLA
Modified: 2021-02-11 00:54 EST (History)
4 users (show)

See Also:


Attachments
A 7-zip file containing the source code and output (6 files) (2.08 KB, application/octet-stream)
2020-03-19 03:24 EDT, Paul Holder CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Holder CLA 2020-03-19 03:24:44 EDT
Created attachment 282136 [details]
A 7-zip file containing the source code and output (6 files)

I just downloaded eclipse-jee-2020-03-R-incubation-win32-x86_64.zip and then installed the marketplace plug-in to enable support for JDK14.  I then attempted to create some example code to test some of the JDK14 features.  I will attach the code I tested with, but here are the problems I encountered:

1 - generation of multi-line strings is WRONG, starts with a spurious newline
2 - a bad interaction with nullity checking and records
3 - an incorrect warning about nullity annotations being redundant
4 - inability to use the new -XX:+ShowCodeDetailsInExceptionMessages
5 - unclear interaction with the maven support

Let me explain each one:


1. generation of multi-line strings is WRONG, starts with a spurious newline
The code looks like
  private static final String MESSAGE = """
          This is a multi-line
          message that is super-
          exciting!""";
...
    System.out.println("Playing with recent JDK features:");
    System.out.println(MESSAGE);

and the generated output is:
Playing with recent JDK features:

This is a multi-line
message that is super-
exciting!

that blank line is there is NOT CORRECT.


2. a bad interaction with nullity checking and records
The package-info.java file declares the package with @org.eclipse.jdt.annotation.NonNullByDefault

and the record definition
  private record Point(long x, long y)
generates an error (I have nullity warnings treated as errors):
The method equals(@NonNull Object) from JDK14Testing.Point cannot implement the corresponding method from Record due to incompatible nullness constraints

There is no obvious way around that but to turn off nullity checking for the record definition, which I did by adding:
@org.eclipse.jdt.annotation.NonNullByDefault({})
private record Point(long x, long y)

but this led to the next issue.


3. an incorrect warning about nullity annotations being redundant
The whole package has
@org.eclipse.jdt.annotation.NonNullByDefault
but when having
@org.eclipse.jdt.annotation.NonNullByDefault({})
private record Point(long x, long y)
I was getting a spurious warning that the annotation setting nullity to default (off) NonNullByDefault({}) was redundant in the multiple places I had applied it.  At some point it went away, and I have been unable to clearly reproduce it since.  :(


4. inability to use the new -XX:+ShowCodeDetailsInExceptionMessages
I wanted to test the new Null Pointer Exception (NPE) messages, but there
is not clear way to enable that in the Eclipse settings.
I got a message like:
Exception in thread "main" java.lang.NullPointerException
at JDK14Testing.testBetterNPE(JDK14Testing.java:50)
at JDK14Testing.doTest(JDK14Testing.java:43)
at JDK14TestMain.main(JDK14TestMain.java:8)
instead of:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.equals(Object)" because "object" is null
at JDK14Testing.testBetterNPE(JDK14Testing.java:55)
at JDK14Testing.doTest(JDK14Testing.java:48)
at JDK14TestMain.main(JDK14TestMain.java:8)

(note line numbers changed because I edited code between examples)


5. unclear interaction with the maven support
It's a maven project, and initially, in eclipse, I enabled the JDK14 setting "enable preview features".  This meant I could build/run the code from inside Eclipse, but when I later tried to build from a mvn command line, I got an error because I hadn't edited the maven POM to include the maven-compiler-plugin config:
<compilerArgs>
  <arg>--enable-preview</arg>
</compilerArgs>
There may be nothing much Eclipse can do to help here, but perhaps it could synchronize the settings from the POM or warn on it or something.
Comment 1 Jay Arthanareeswaran CLA 2020-03-19 06:29:15 EDT
(In reply to Paul Holder from comment #0)
> 1. generation of multi-line strings is WRONG, starts with a spurious newline
> The code looks like
>   private static final String MESSAGE = """
>           This is a multi-line
>           message that is super-
>           exciting!""";
> ...
>     System.out.println("Playing with recent JDK features:");
>     System.out.println(MESSAGE);
> 
> and the generated output is:
> Playing with recent JDK features:
> 
> This is a multi-line
> message that is super-
> exciting!
> 
> that blank line is there is NOT CORRECT.

I can reproduce this. I will look into this. I will let Manoj comment on the other items.

Thanks for the report, BTW. But I think we are going to have to create individual bugs for each issue after looking at other ones as well.
Comment 2 Jay Arthanareeswaran CLA 2020-03-19 06:44:11 EDT
(In reply to Jay Arthanareeswaran from comment #1)
> 
> I can reproduce this. I will look into this. 

Raised bug 561251.
Comment 3 Jay Arthanareeswaran CLA 2020-05-18 03:56:20 EDT
Manoj, can you please list which of the originally reported issues are still pending? I see bug 551483 has been created to cover quite a few null related topics. Also copying Stephan who might be interested in the null annotation related points.
Comment 4 Manoj N Palat CLA 2020-05-18 05:23:09 EDT
(In reply to Jay Arthanareeswaran from comment #3)
> Manoj, can you please list which of the originally reported issues are still
> pending? I see bug 551483 has been created to cover quite a few null related
> topics. Also copying Stephan who might be interested in the null annotation
> related points.

Yep, Jay - I was in the middle of trying this out with various versions of Eclipse especially the master ToT and SDK-I20200515-1930. I don't see the null analysis problems (items 2 and 3) occurring anymore with master or SDK-I20200515-1930 -this must have got fixed along the different fixes that have gone in. - let know if you are able to reproduce this issue still.

Item 4, the Helpful Null Pointer Exception (JEP 358) needs to be investigated under the related bug 551483 under jdt.debug; jdt.core support by that analysis will be taken up if found required.

Item 5 - no expertise in maven/interaction to provide any useful input here.
Comment 5 Manoj N Palat CLA 2020-05-18 05:32:42 EDT
moving this out to 4.17
Comment 6 Stephan Herrmann CLA 2020-05-18 06:04:06 EDT
(In reply to Manoj Palat from comment #4)
> (In reply to Jay Arthanareeswaran from comment #3)
> > Manoj, can you please list which of the originally reported issues are still
> > pending? I see bug 551483 has been created to cover quite a few null related
> > topics. Also copying Stephan who might be interested in the null annotation
> > related points.
> 
> Yep, Jay - I was in the middle of trying this out with various versions of
> Eclipse especially the master ToT and SDK-I20200515-1930. I don't see the
> null analysis problems (items 2 and 3) occurring anymore with master or
> SDK-I20200515-1930 -this must have got fixed along the different fixes that
> have gone in. - let know if you are able to reproduce this issue still.

Has any of this made it into a JUnit test?
 
> Item 5 - no expertise in maven/interaction to provide any useful input here.

These ussues should be filed against m2e - JDT alone cannot solve this.
Feel free to set me on Cc: on the m2e bug, but s.o. needs to drive this from the maven p.o.v. - which is not JDT's job.
Comment 7 Sarika Sinha CLA 2020-05-21 07:47:30 EDT
(In reply to Paul Holder from comment #0)

> 
> 4. inability to use the new -XX:+ShowCodeDetailsInExceptionMessages
> I wanted to test the new Null Pointer Exception (NPE) messages, but there
> is not clear way to enable that in the Eclipse settings.
> I got a message like:
> Exception in thread "main" java.lang.NullPointerException
> at JDK14Testing.testBetterNPE(JDK14Testing.java:50)
> at JDK14Testing.doTest(JDK14Testing.java:43)
> at JDK14TestMain.main(JDK14TestMain.java:8)
> instead of:
> Exception in thread "main" java.lang.NullPointerException: Cannot invoke
> "Object.equals(Object)" because "object" is null
> at JDK14Testing.testBetterNPE(JDK14Testing.java:55)
> at JDK14Testing.doTest(JDK14Testing.java:48)
> at JDK14TestMain.main(JDK14TestMain.java:8)
> 
> (note line numbers changed because I edited code between examples)
> 
You can provide the command line details in VM arguments  section of "Arguments" tab in the launch configuration.
Comment 8 Stephan Herrmann CLA 2020-05-21 07:53:52 EDT
(In reply to Sarika Sinha from comment #7)
> (In reply to Paul Holder from comment #0)
> 
> > 
> > 4. inability to use the new -XX:+ShowCodeDetailsInExceptionMessages
> > I wanted to test the new Null Pointer Exception (NPE) messages, but there
> > is not clear way to enable that in the Eclipse settings.
> > I got a message like:
> > Exception in thread "main" java.lang.NullPointerException
> > at JDK14Testing.testBetterNPE(JDK14Testing.java:50)
> > at JDK14Testing.doTest(JDK14Testing.java:43)
> > at JDK14TestMain.main(JDK14TestMain.java:8)
> > instead of:
> > Exception in thread "main" java.lang.NullPointerException: Cannot invoke
> > "Object.equals(Object)" because "object" is null
> > at JDK14Testing.testBetterNPE(JDK14Testing.java:55)
> > at JDK14Testing.doTest(JDK14Testing.java:48)
> > at JDK14TestMain.main(JDK14TestMain.java:8)
> > 
> > (note line numbers changed because I edited code between examples)
> > 
> You can provide the command line details in VM arguments  section of
> "Arguments" tab in the launch configuration.

Has it been discussed to add a more user friendly checkbox for this option specifically to the launch dialog? Perhaps it could even be made the default for Java 14 launches?
Comment 9 Sarika Sinha CLA 2020-05-21 08:12:46 EDT
(In reply to Stephan Herrmann from comment #8)

> > > 
> > You can provide the command line details in VM arguments  section of
> > "Arguments" tab in the launch configuration.
> 
> Has it been discussed to add a more user friendly checkbox for this option
> specifically to the launch dialog? Perhaps it could even be made the default
> for Java 14 launches?

Yes, https://bugs.eclipse.org/bugs/show_bug.cgi?id=551483#c2
Comment 10 Manoj N Palat CLA 2020-11-13 02:56:58 EST
(In reply to Stephan Herrmann from comment #6)

> Has any of this made it into a JUnit test?
>  
> > Item 5 - no expertise in maven/interaction to provide any useful input here.
> 
> These ussues should be filed against m2e - JDT alone cannot solve this.
> Feel free to set me on Cc: on the m2e bug, but s.o. needs to drive this from
> the maven p.o.v. - which is not JDT's job.


Now there are two items pending -

(1) check for any junits for these

(2)driving this with m2e - @Sravan: can you drive this?

moving these to 4.19
Comment 11 Sravan Kumar Lakkimsetti CLA 2020-11-16 03:49:08 EST
(In reply to Manoj Palat from comment #10)
> (In reply to Stephan Herrmann from comment #6)
> 
> > Has any of this made it into a JUnit test?
> >  
> > > Item 5 - no expertise in maven/interaction to provide any useful input here.
> > 
> > These ussues should be filed against m2e - JDT alone cannot solve this.
> > Feel free to set me on Cc: on the m2e bug, but s.o. needs to drive this from
> > the maven p.o.v. - which is not JDT's job.
> 
> 
> Now there are two items pending -
> 
> (1) check for any junits for these
> 
> (2)driving this with m2e - @Sravan: can you drive this?
> 
> moving these to 4.19

Tycho-compiler-plugin is designed specifically for this. Tycho can read jdt preferences and use them for compilation. this is not possible with maven-compiler-plugin. With tycho you need update pom.xml to keep the options in sync

Here is the documentation for tycho compiler plugin https://www.eclipse.org/tycho/sitedocs/tycho-compiler-plugin/compile-mojo.html
Comment 12 Sravan Kumar Lakkimsetti CLA 2020-11-16 03:52:37 EST
here is the specific setting that can be used to pass eclipse settings to tycho compiler(in this specific case we use ecj)

https://www.eclipse.org/tycho/sitedocs/tycho-compiler-plugin/compile-mojo.html#useProjectSettings
Comment 13 Sravan Kumar Lakkimsetti CLA 2021-02-11 00:54:31 EST
To use ecj compiler with project specific options we need to use Tycho. 

Closing this for now. Please reopen if you need any more help