Open josebraz123 opened 5 months ago
It was great if netBeans could detect and show the syntactic error. I think the switch (){ } looks a lot like a method and something goes wrong when parsing.
Well, NetBeans uses javac for parsing, and the same Unexpected tree
error is shown in a notification. I'm curious that the JavacParser
call at https://github.com/apache/netbeans/blob/master/java/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java#L742 doesn't catch the AssertionError
and wrap it in an IOException
, which is possibly how to read the documentation for that method?? cc/ @lahodaj @mbien - thoughts?
fixed the formatting a bit so that the log doesn't break the markup.
thanks for providing the reproducer!
Thanks 😉
Com os melhores cumprimentos, @.***
From: Michael Bien @.> Sent: Thursday, June 6, 2024 1:23 PM To: apache/netbeans @.> Cc: José Braz @.>; Author @.> Subject: Re: [apache/netbeans] Syntactic error missing when inserting a switch in enum body (Issue #7437)
ATENÇÃO: Este email foi originado fora do IPS. Por favor, não clique em links nem abra anexos, a não ser que conheça o remetente e saiba que o seu conteúdo é seguro.
fixed the formatting a bit so that the log doesn't break the markup.
thanks for providing the reproducer!
— Reply to this email directly, view it on GitHubhttps://github.com/apache/netbeans/issues/7437#issuecomment-2152274895, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BI6V33KGCMRQSS43WHP7CVLZGBIDNAVCNFSM6AAAAABI3KHIZSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJSGI3TIOBZGU. You are receiving this because you authored the thread.Message ID: @.**@.>>
Well, NetBeans uses javac for parsing, and the same
Unexpected tree
error is shown in a notification. I'm curious that theJavacParser
call at https://github.com/apache/netbeans/blob/master/java/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java#L742 doesn't catch theAssertionError
and wrap it in anIOException
, which is possibly how to read the documentation for that method?? cc/ @lahodaj @mbien - thoughts?
@neilcsmith-net this doesn't seem to make a (big) difference unfortunately since IOEs are caught and rethrown as ParseExceptions
, e.g https://github.com/apache/netbeans/blob/f6e767325d4c98363794065ba60e559424ae1c2a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java#L535-L539
I quickly tested this using the reproducer and it would still end up in the notifications instead of the editor error annotations.
javac output for
public enum EPOCH {
CLASSIC, CONTEMPORARY, NONE;
switch (this){ // (no sintactic error message on the left):
case CLASSIC : return "Classic";
case CONTEMPORARY : return "Contemporary";
default : return "None";
}
}
is
src/main/java/EPOCH.java:8: error: <identifier> expected
}
^
1 error
btw
Any progress? netbeans 23 with same problem
Yes, there's progress. I believe this should be fixed in javac by: https://bugs.openjdk.org/browse/JDK-8337976 so when we adopt javac from JDK 24, this should get fixed.
Apache NetBeans version
Apache NetBeans 22
What happened
A student (students are great bug hunters) when asked to create a toString for an enum inserted a switch/case instruction directly in the enum body and it did not show any syntactic error ... instead, when compiling, it just throws an exception:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX It was great if netBeans could detect and show the syntactic error. I think the switch (){ } looks a lot like a method and something goes wrong when parsing.
Moreover, when trying to refactor/rename the file with the main class the following exception was thrown:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Below the messages.log file content (is there a way to submit a few files here, namely the project?)
Language / Project Type / NetBeans Component
Java with Ant
How to reproduce
1, create a project java with ant -> java application
create a class named ClassHasEnum
create an enum named EPOCH with values CLASSIC, CONTEMPORARY, NONE;
insert a switch in the enum body
Add an attribute private EPOCH epoch to class ClassHasEnum
On main method create an ClassHasEnum object: ClassHasEnum oa = new ClassHasEnum();
Menu Debug -> Debug Project (or Ctrl+F5) and the appError class appears missing
if you try shift+F11, yes it detects the syntactic error
Hope it helps improving "our" great IDE ;-) All the best, José
Did this work correctly in an earlier version?
No / Don't know
Operating System
Windows 10 and 11
JDK
JDK 21
Apache NetBeans packaging
Apache NetBeans provided installer
Anything else
Yes, everytime because is a syntactic error ;-)
Are you willing to submit a pull request?
No