From kan.izh at gmail.com Wed Aug 2 23:30:22 2023 From: kan.izh at gmail.com (Anatoly Kupriyanov) Date: Thu, 3 Aug 2023 00:30:22 +0100 Subject: [JEP 430] StringTemplate should be generic? Message-ID: As I see values are always Object. However, for type-safety it would be good to have bounded types: public interface StringTemplate { List values(); ... } E.g. a Json template should require values to be JSONObject. In this case it would be possible to compose fragments with type-safety like this: String name = "Joan Smith"; String phone = null; boolean residential = true; JSONObject address = JSON.""" { "residential": \{JSON.primitive(residential)}, "postcode": \{JSON.primitive(postcode)} } """; JSONObject doc = JSON.""" { "name": \{JSON.primitive(name)}, "phone": \{JSON.primitive(phone)}, "address": \{address} } """; There are some good ideas implemented in C# for type-safety, e.g. it allows to have different overloads for different types for avoiding run-time type matching. See AppendFormatted here https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/improved-interpolated-strings -- WBR, Anatoly. -------------- next part -------------- An HTML attachment was scrubbed... URL: From duke at openjdk.org Thu Aug 3 13:49:56 2023 From: duke at openjdk.org (duke) Date: Thu, 3 Aug 2023 13:49:56 GMT Subject: [patterns-instanceof-primitive] Withdrawn: 8303374: Compiler Implementation for Primitive types in patterns, instanceof, and switch In-Reply-To: References: Message-ID: <5HQL42CtqO9cylAYBBusEGldej2jB1CuhT4TQlS8KLk=.d9d7f25a-1bee-46a6-aa52-392c5d4bfa59@github.com> On Tue, 7 Mar 2023 13:23:29 GMT, Aggelos Biboudis wrote: > Prototype implementation for primitive types in patterns, instanceof, and switch. > > draft JEP: https://openjdk.org/jeps/8288476 > > draft spec: https://cr.openjdk.org/~abimpoudis/instanceof/latest/ This pull request has been closed without being integrated. ------------- PR: https://git.openjdk.org/amber/pull/91 From ice1000kotlin at foxmail.com Sat Aug 5 04:45:44 2023 From: ice1000kotlin at foxmail.com (=?ISO-8859-1?B?VGVzbGEgWmhhbmc=?=) Date: Sat, 5 Aug 2023 00:45:44 -0400 Subject: A potential JDK 20 bug Message-ID: Trying to run the following code with jdk 20 leads to java.lang.VerifyError: public class Java20 { sealed interface AST {} record Lam(String name, AST ast) implements AST {} record Var(String name) implements AST {} record Pair(AST a, AST b) {} static void test(AST x, AST y) { System.out.println(switch (new Pair(x, y)) { case Pair(Lam(var a, var b), var c) -> a + b + c; case Pair(var a, Lam b) -> b.toString(); default -> "1919"; }); } public static void main(String[] args) { test(new Var("a"), new Var("b")); } } The exception is: Error: Unable to initialize main class com.intellij.bug.Java20 in module intellij.bug.reports Caused by: java.lang.VerifyError: Bad local variable type Exception Details:   Location:     com/intellij/bug/Java20.test(Lcom/intellij/bug/Java20$AST;Lcom/intellij/bug/Java20$AST;)V @192: aload   Reason:     Type top (current frame, locals[10]) is not assignable to reference type   Current Frame:     bci: @192     flags: { }     locals: { 'com/intellij/bug/Java20$AST', 'com/intellij/bug/Java20$AST', 'com/intellij/bug/Java20$Pair', integer, 'com/intellij/bug/Java20$Pair', top, top, top, top, 'com/intellij/bug/Java20$AST', top, 'com/intellij/bug/Java20$AST', integer }     stack: { 'java/io/PrintStream' }   Bytecode:     0000000: b200 07bb 000d 592a 2bb7 000f 59b8 0012     0000010: 574d 033e 2c1d ba00 1800 00ab 0000 00b2     0000020: 0000 0001 0000 0000 0000 0011 2c3a 0419     0000030: 04b6 001c 3a0b 0336 0c19 0b15 0cba 0020     0000040: 0000 aa00 0000 0086 ffff ffff 0000 0001     0000050: 0000 0056 0000 001a 0000 0056 190b c000     0000060: 213a 0519 04b6 0023 3a0d 190d 3a06 1905     0000070: b600 263a 0d19 0d3a 0719 05b6 002a 3a0d     0000080: 190d 3a08 1907 1908 b800 2d19 06b8 002d     0000090: ba00 3300 00a7 003d 190b 3a09 1909 c600     00000a0: 2219 04b6 0023 3a0d 190d c100 2199 000d     00000b0: 190d c000 213a 0aa7 0009 0536 0ca7 ff7c     00000c0: 190a b600 37a7 000d 043e a7ff 4a12 3aa7     00000d0: 0003 b600 3ca7 0011 4dbb 0044 592c b600     00000e0: 462c b700 47bf b1                         Exception Handler Table:     bci [49, 52] => handler: 216     bci [101, 104] => handler: 216     bci [112, 115] => handler: 216     bci [123, 126] => handler: 216     bci [163, 166] => handler: 216   Stackmap Table:     full_frame(@20,{Object[#97],Object[#97],Object[#13],Integer},{Object[#61]})     same_locals_1_stack_item_frame(@44,Object[#61])     full_frame(@57,{Object[#97],Object[#97],Object[#13],Integer,Object[#13],Top,Top,Top,Top,Top,Top,Object[#97],Integer},{Object[#61]})     same_locals_1_stack_item_frame(@92,Object[#61])     same_locals_1_stack_item_frame(@152,Object[#61])     full_frame(@186,{Object[#97],Object[#97],Object[#13],Integer,Object[#13],Top,Top,Top,Top,Object[#97],Top,Object[#97],Integer},{Object[#61]})     same_locals_1_stack_item_frame(@192,Object[#61])     full_frame(@200,{Object[#97],Object[#97],Object[#13],Integer,Object[#13],Top,Top,Top,Top,Top,Top,Object[#97],Integer},{Object[#61]})     full_frame(@205,{Object[#97],Object[#97],Object[#13],Integer},{Object[#61]})     full_frame(@210,{Object[#97],Object[#97]},{Object[#61],Object[#46]})     same_locals_1_stack_item_frame(@216,Object[#66])     same_frame(@230) Env: openjdk version "20.0.2" 2023-07-18 OpenJDK Runtime Environment (build 20.0.2+10) OpenJDK 64-Bit Server VM (build 20.0.2+10, mixed mode, sharing) Best regards, Tesla Zhang -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidalayachew at gmail.com Sun Aug 6 23:31:14 2023 From: davidalayachew at gmail.com (David Alayachew) Date: Sun, 6 Aug 2023 19:31:14 -0400 Subject: Illegal field name when trying to compile with a javax.swing.Action In-Reply-To: References: Message-ID: Hello Amber Dev Team, I ran into a problem that I am not sure what the cause is. It only seems to occur when I am using unnamed variables. Here are the commands that I am using, as well as their outputs. $ javac -g -Xlint:all,-preview,-serial -Xdiags:verbose --enable-preview --source 21 GUI.java Note: GUI.java uses preview features of Java SE 21. Note: Recompile with -Xlint:preview for details. $ java --enable-preview GUI Error: LinkageError occurred while loading main class GUI java.lang.ClassFormatError: Illegal field name "" in class GUI And here is the file that I am using. import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.JButton; import java.util.function.BiFunction; public class GUI { public static void main(String[] args) { new GUI(null, null); } public GUI(final Object characterType, final Object icon) { } private Object createConstraintPanel() { final JPanel constraintPanel = new JPanel(); final JButton button = new JButton(); CREATE_INPUT_SANITIZATION: { BUTTON_ACTION_LISTENER: { button .addActionListener ( _ -> { final BiFunction createLabel = (text, width) -> { return null; } ; final JButton remove = new JButton(); remove .addActionListener ( _ -> { } ); } ) ; } } return constraintPanel; } } Technically, this issue also occurs if even 1 of the 2 unnamed variables is turned into a real variable. But regardless, the point is, this fails at run time. Please let me know if there is anything I am missing. Thank you for your time and help! David Alayachew On Tue, Jul 18, 2023 at 1:54?AM David Alayachew wrote: > Ok, ty for the heads up. > > On Tue, Jul 18, 2023 at 1:18?AM - wrote: > >> Hi David, >> Please do not ask for technical support in the development mailing list. >> There's no proof that this issue is with the core libraries instead of the >> Java compiler or another component. >> I have already downloaded your zip, compiled the 4 files with JDK 22 (my >> local dev build for another unrelated patch) javac --enable-preview >> -release 22 *.java and java --enable-preview ToDoList, which just shows up >> a UI without any crash. Without enable-preview, yoru code does not compile >> at all for the usage of _ as an identifier. >> >> This is most likely a problem with the compiler you are using; you have a >> gpj file, which probably means you are using jGrasp. Please report this >> issue to the relevant parties (i.e. the 3rd-party IDE or whatever supports >> using _ as identifer without --enable-preview) instead. >> >> Chen Liang >> >> On Tue, Jul 18, 2023 at 11:43?AM David Alayachew < >> davidalayachew at gmail.com> wrote: >> >>> Wait, nevermind. Don't ignore. I was able to recreate this issue on the >>> command line using the abovementioned JDK. Could someone come back and take >>> a look at this please? >>> >>> Sorry for jerking everyone around here. I have multiple JDK's and got >>> mixed up on which one I was using. >>> >>> On Sun, Jul 16, 2023 at 2:26?AM David Alayachew < >>> davidalayachew at gmail.com> wrote: >>> >>>> Hmmmm, this one might actually be IDE specific. Please ignore. >>>> >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidalayachew at gmail.com Sun Aug 6 23:31:54 2023 From: davidalayachew at gmail.com (David Alayachew) Date: Sun, 6 Aug 2023 19:31:54 -0400 Subject: Illegal field name when trying to compile with a javax.swing.Action In-Reply-To: References: Message-ID: Also, here is my version info. $ java --version openjdk 21-ea 2023-09-19 OpenJDK Runtime Environment (build 21-ea+31-2444) OpenJDK 64-Bit Server VM (build 21-ea+31-2444, mixed mode, sharing) $ javac --version javac 21-ea On Sun, Aug 6, 2023 at 7:31?PM David Alayachew wrote: > Hello Amber Dev Team, > > I ran into a problem that I am not sure what the cause is. It only seems > to occur when I am using unnamed variables. > > > Here are the commands that I am using, as well as their outputs. > > > $ javac -g -Xlint:all,-preview,-serial -Xdiags:verbose --enable-preview > --source 21 GUI.java > Note: GUI.java uses preview features of Java SE 21. > Note: Recompile with -Xlint:preview for details. > > > $ java --enable-preview GUI > Error: LinkageError occurred while loading main class GUI > java.lang.ClassFormatError: Illegal field name "" in class GUI > > And here is the file that I am using. > > > import javax.swing.JPanel; > import javax.swing.JLabel; > import javax.swing.JButton; > import java.util.function.BiFunction; > > public class GUI > { > > public static void main(String[] args) > { > > new GUI(null, null); > > } > > public GUI(final Object characterType, final Object icon) > { > > } > > private Object createConstraintPanel() > { > > final JPanel constraintPanel = new JPanel(); > final JButton button = new JButton(); > > CREATE_INPUT_SANITIZATION: > { > > BUTTON_ACTION_LISTENER: > { > > button > .addActionListener > ( > _ -> > { > > final BiFunction createLabel > = > (text, width) -> > { > > return null; > > } > ; > > final JButton remove = new JButton(); > remove > .addActionListener > ( > _ -> > { > > > } > ); > > } > ) > ; > > } > > } > > return constraintPanel; > > } > > } > > Technically, this issue also occurs if even 1 of the 2 unnamed variables > is turned into a real variable. But regardless, the point is, this fails at > run time. > > Please let me know if there is anything I am missing. > > Thank you for your time and help! > David Alayachew > > > On Tue, Jul 18, 2023 at 1:54?AM David Alayachew > wrote: > >> Ok, ty for the heads up. >> >> On Tue, Jul 18, 2023 at 1:18?AM - wrote: >> >>> Hi David, >>> Please do not ask for technical support in the development mailing list. >>> There's no proof that this issue is with the core libraries instead of the >>> Java compiler or another component. >>> I have already downloaded your zip, compiled the 4 files with JDK 22 (my >>> local dev build for another unrelated patch) javac --enable-preview >>> -release 22 *.java and java --enable-preview ToDoList, which just shows up >>> a UI without any crash. Without enable-preview, yoru code does not compile >>> at all for the usage of _ as an identifier. >>> >>> This is most likely a problem with the compiler you are using; you have >>> a gpj file, which probably means you are using jGrasp. Please report this >>> issue to the relevant parties (i.e. the 3rd-party IDE or whatever supports >>> using _ as identifer without --enable-preview) instead. >>> >>> Chen Liang >>> >>> On Tue, Jul 18, 2023 at 11:43?AM David Alayachew < >>> davidalayachew at gmail.com> wrote: >>> >>>> Wait, nevermind. Don't ignore. I was able to recreate this issue on the >>>> command line using the abovementioned JDK. Could someone come back and take >>>> a look at this please? >>>> >>>> Sorry for jerking everyone around here. I have multiple JDK's and got >>>> mixed up on which one I was using. >>>> >>>> On Sun, Jul 16, 2023 at 2:26?AM David Alayachew < >>>> davidalayachew at gmail.com> wrote: >>>> >>>>> Hmmmm, this one might actually be IDE specific. Please ignore. >>>>> >>>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From forax at univ-mlv.fr Mon Aug 7 19:10:49 2023 From: forax at univ-mlv.fr (Remi Forax) Date: Mon, 7 Aug 2023 21:10:49 +0200 (CEST) Subject: Illegal field name when trying to compile with a javax.swing.Action In-Reply-To: References: Message-ID: <1734640837.9801388.1691435449049.JavaMail.zimbra@univ-eiffel.fr> Hi David, thanks for the bug report. I was able to reproduce the issue with the latest early acces of 22, There is no issue if "-g" is not specified, so the bug seems to be in the debug information that are added to the classfile. javac -g --enable-preview --source 22 GUI.java Here is a simpler reproducer import java.util.function.Consumer ; public class GUI { public static void main ( String [] args) { Consumer < String > op = _ -> {}; } } javap shows the issue, the LocalVariableTable is generated with the name "" private static void lambda$main$0(java.lang.String); descriptor: (Ljava/lang/String;)V flags: (0x100a) ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC Code: stack=0, locals=1, args_size=1 0: return LineNumberTable: line 5: 0 LocalVariableTable: Start Length Slot Name Signature 0 1 0 Ljava/lang/String; The JVM spec 4.7.13 said " name_index The value of the name_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must contain a CONSTANT_Utf8_info structure representing a valid unqualified name denoting a local variable ( [ https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.2.2 | ?4.2.2 ] ). " And 4.2.2 said that the string must have at least one code point, so "" is an invalid name, rightly rejected by the VM (the error message is just not great, it's not about a field but a local variable name, here a parameter inside the LocalVariableTable). So it's a bug in the compiler, I see two ways to fix it, either do not generate a line in the LocalVariableTable if the parameter is unamed or use "_" instead. regards, R?mi > From: "David Alayachew" > To: "amber-dev" > Sent: Sunday, August 6, 2023 4:31:54 PM > Subject: Re: Illegal field name when trying to compile with a javax.swing.Action > Also, here is my version info. > $ java --version > openjdk 21-ea 2023-09-19 > OpenJDK Runtime Environment (build 21-ea+31-2444) > OpenJDK 64-Bit Server VM (build 21-ea+31-2444, mixed mode, sharing) > $ javac --version > javac 21-ea > On Sun, Aug 6, 2023 at 7:31 PM David Alayachew < [ > mailto:davidalayachew at gmail.com | davidalayachew at gmail.com ] > wrote: >> Hello Amber Dev Team, >> I ran into a problem that I am not sure what the cause is. It only seems to >> occur when I am using unnamed variables. >> Here are the commands that I am using, as well as their outputs. >> $ javac -g -Xlint:all,-preview,-serial -Xdiags:verbose --enable-preview --source >> 21 GUI.java >> Note: GUI.java uses preview features of Java SE 21. >> Note: Recompile with -Xlint:preview for details. >> $ java --enable-preview GUI >> Error: LinkageError occurred while loading main class GUI >> java.lang.ClassFormatError: Illegal field name "" in class GUI >> And here is the file that I am using. >> import javax.swing.JPanel; >> import javax.swing.JLabel; >> import javax.swing.JButton; >> import java.util.function.BiFunction; >> public class GUI >> { >> public static void main(String[] args) >> { >> new GUI(null, null); >> } >> public GUI(final Object characterType, final Object icon) >> { >> } >> private Object createConstraintPanel() >> { >> final JPanel constraintPanel = new JPanel(); >> final JButton button = new JButton(); >> CREATE_INPUT_SANITIZATION: >> { >> BUTTON_ACTION_LISTENER: >> { >> button >> .addActionListener >> ( >> _ -> >> { >> final BiFunction createLabel = >> (text, width) -> >> { >> return null; >> } >> ; >> final JButton remove = new JButton(); >> remove >> .addActionListener >> ( >> _ -> >> { >> } >> ); >> } >> ) >> ; >> } >> } >> return constraintPanel; >> } >> } >> Technically, this issue also occurs if even 1 of the 2 unnamed variables is >> turned into a real variable. But regardless, the point is, this fails at run >> time. >> Please let me know if there is anything I am missing. >> Thank you for your time and help! >> David Alayachew >> On Tue, Jul 18, 2023 at 1:54 AM David Alayachew < [ >> mailto:davidalayachew at gmail.com | davidalayachew at gmail.com ] > wrote: >>> Ok, ty for the heads up. >>> On Tue, Jul 18, 2023 at 1:18 AM - < [ mailto:liangchenblue at gmail.com | >>> liangchenblue at gmail.com ] > wrote: >>>> Hi David, >>>> Please do not ask for technical support in the development mailing list. There's >>>> no proof that this issue is with the core libraries instead of the Java >>>> compiler or another component. >>>> I have already downloaded your zip, compiled the 4 files with JDK 22 (my local >>>> dev build for another unrelated patch) javac --enable-preview -release 22 >>>> *.java and java --enable-preview ToDoList, which just shows up a UI without any >>>> crash. Without enable-preview, yoru code does not compile at all for the usage >>>> of _ as an identifier. >>>> This is most likely a problem with the compiler you are using; you have a gpj >>>> file, which probably means you are using jGrasp. Please report this issue to >>>> the relevant parties (i.e. the 3rd-party IDE or whatever supports using _ as >>>> identifer without --enable-preview) instead. >>>> Chen Liang >>>> On Tue, Jul 18, 2023 at 11:43 AM David Alayachew < [ >>>> mailto:davidalayachew at gmail.com | davidalayachew at gmail.com ] > wrote: >>>>> Wait, nevermind. Don't ignore. I was able to recreate this issue on the command >>>>> line using the abovementioned JDK. Could someone come back and take a look at >>>>> this please? >>>>> Sorry for jerking everyone around here. I have multiple JDK's and got mixed up >>>>> on which one I was using. >>>>> On Sun, Jul 16, 2023 at 2:26 AM David Alayachew < [ >>>>> mailto:davidalayachew at gmail.com | davidalayachew at gmail.com ] > wrote: >>>>>> Hmmmm, this one might actually be IDE specific. Please ignore. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidalayachew at gmail.com Mon Aug 7 19:17:07 2023 From: davidalayachew at gmail.com (David Alayachew) Date: Mon, 7 Aug 2023 15:17:07 -0400 Subject: Illegal field name when trying to compile with a javax.swing.Action In-Reply-To: <1734640837.9801388.1691435449049.JavaMail.zimbra@univ-eiffel.fr> References: <1734640837.9801388.1691435449049.JavaMail.zimbra@univ-eiffel.fr> Message-ID: Hello R?mi, Thank you for your response! And thanks for checking. I had tried to debug this issue earlier on, but couldn't quite pin down the source. I am completely ignorant about the LocalVariableTable, so I can't respond to that or the spec stuff. If there is any info I can provide, please let me know. Thank you for your time and help! David Alayachew On Mon, Aug 7, 2023 at 3:10?PM Remi Forax wrote: > Hi David, > thanks for the bug report. > > I was able to reproduce the issue with the latest early acces of 22, > There is no issue if "-g" is not specified, so the bug seems to be in the > debug information that are added to the classfile. > > javac -g --enable-preview --source 22 GUI.java > > Here is a simpler reproducer > > > import java.util.function.Consumer; > > public class GUI { > public static void main(String[] args) { > Consumer op = _ -> {}; > } > } > > > javap shows the issue, the LocalVariableTable is generated with the name "" > > private static void lambda$main$0(java.lang.String); > descriptor: (Ljava/lang/String;)V > flags: (0x100a) ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC > Code: > stack=0, locals=1, args_size=1 > 0: return > LineNumberTable: > line 5: 0 > LocalVariableTable: > Start Length Slot Name Signature > 0 1 0 Ljava/lang/String; > > The JVM spec 4.7.13 said > " > name_index > > The value of the name_index item must be a valid index into the > constant_pool table. The constant_pool entry at that index must contain a > CONSTANT_Utf8_info structure representing a valid unqualified name > denoting a local variable (?4.2.2 > > ). > > " > > And 4.2.2 said that the string must have at least one code point, so "" is > an invalid name, rightly rejected by the VM (the error message is just not > great, it's not about a field but a local variable name, here a parameter > inside the LocalVariableTable). > > So it's a bug in the compiler, I see two ways to fix it, either do not > generate a line in the LocalVariableTable if the parameter is unamed or use > "_" instead. > > regards, > R?mi > > ------------------------------ > > *From: *"David Alayachew" > *To: *"amber-dev" > *Sent: *Sunday, August 6, 2023 4:31:54 PM > *Subject: *Re: Illegal field name when trying to compile with a > javax.swing.Action > > Also, here is my version info. > > > $ java --version > openjdk 21-ea 2023-09-19 > OpenJDK Runtime Environment (build 21-ea+31-2444) > OpenJDK 64-Bit Server VM (build 21-ea+31-2444, mixed mode, sharing) > > > $ javac --version > javac 21-ea > > > > On Sun, Aug 6, 2023 at 7:31?PM David Alayachew > wrote: > >> Hello Amber Dev Team, >> >> I ran into a problem that I am not sure what the cause is. It only seems >> to occur when I am using unnamed variables. >> >> >> Here are the commands that I am using, as well as their outputs. >> >> >> $ javac -g -Xlint:all,-preview,-serial -Xdiags:verbose --enable-preview >> --source 21 GUI.java >> Note: GUI.java uses preview features of Java SE 21. >> Note: Recompile with -Xlint:preview for details. >> >> >> $ java --enable-preview GUI >> Error: LinkageError occurred while loading main class GUI >> java.lang.ClassFormatError: Illegal field name "" in class GUI >> >> And here is the file that I am using. >> >> >> import javax.swing.JPanel; >> import javax.swing.JLabel; >> import javax.swing.JButton; >> import java.util.function.BiFunction; >> >> public class GUI >> { >> >> public static void main(String[] args) >> { >> >> new GUI(null, null); >> >> } >> >> public GUI(final Object characterType, final Object icon) >> { >> >> } >> >> private Object createConstraintPanel() >> { >> >> final JPanel constraintPanel = new JPanel(); >> final JButton button = new JButton(); >> >> CREATE_INPUT_SANITIZATION: >> { >> >> BUTTON_ACTION_LISTENER: >> { >> >> button >> .addActionListener >> ( >> _ -> >> { >> >> final BiFunction >> createLabel = >> (text, width) -> >> { >> >> return null; >> >> } >> ; >> >> final JButton remove = new JButton(); >> remove >> .addActionListener >> ( >> _ -> >> { >> >> >> } >> ); >> >> } >> ) >> ; >> >> } >> >> } >> >> return constraintPanel; >> >> } >> >> } >> >> Technically, this issue also occurs if even 1 of the 2 unnamed variables >> is turned into a real variable. But regardless, the point is, this fails at >> run time. >> >> Please let me know if there is anything I am missing. >> >> Thank you for your time and help! >> David Alayachew >> >> >> On Tue, Jul 18, 2023 at 1:54?AM David Alayachew >> wrote: >> >>> Ok, ty for the heads up. >>> >>> On Tue, Jul 18, 2023 at 1:18?AM - wrote: >>> >>>> Hi David, >>>> Please do not ask for technical support in the development mailing >>>> list. There's no proof that this issue is with the core libraries instead >>>> of the Java compiler or another component. >>>> I have already downloaded your zip, compiled the 4 files with JDK 22 >>>> (my local dev build for another unrelated patch) javac --enable-preview >>>> -release 22 *.java and java --enable-preview ToDoList, which just shows up >>>> a UI without any crash. Without enable-preview, yoru code does not compile >>>> at all for the usage of _ as an identifier. >>>> >>>> This is most likely a problem with the compiler you are using; you have >>>> a gpj file, which probably means you are using jGrasp. Please report this >>>> issue to the relevant parties (i.e. the 3rd-party IDE or whatever supports >>>> using _ as identifer without --enable-preview) instead. >>>> >>>> Chen Liang >>>> >>>> On Tue, Jul 18, 2023 at 11:43?AM David Alayachew < >>>> davidalayachew at gmail.com> wrote: >>>> >>>>> Wait, nevermind. Don't ignore. I was able to recreate this issue on >>>>> the command line using the abovementioned JDK. Could someone come back and >>>>> take a look at this please? >>>>> >>>>> Sorry for jerking everyone around here. I have multiple JDK's and got >>>>> mixed up on which one I was using. >>>>> >>>>> On Sun, Jul 16, 2023 at 2:26?AM David Alayachew < >>>>> davidalayachew at gmail.com> wrote: >>>>> >>>>>> Hmmmm, this one might actually be IDE specific. Please ignore. >>>>>> >>>>> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From florent.guillaume at gmail.com Tue Aug 8 17:59:34 2023 From: florent.guillaume at gmail.com (Florent Guillaume) Date: Tue, 8 Aug 2023 19:59:34 +0200 Subject: Illegal field name when trying to compile with a javax.swing.Action In-Reply-To: <1734640837.9801388.1691435449049.JavaMail.zimbra@univ-eiffel.fr> References: <1734640837.9801388.1691435449049.JavaMail.zimbra@univ-eiffel.fr> Message-ID: Hi, I believe this is https://github.com/openjdk/jdk/pull/15083 Florent On Mon, Aug 7, 2023 at 9:12?PM Remi Forax wrote: > Hi David, > thanks for the bug report. > > I was able to reproduce the issue with the latest early acces of 22, > There is no issue if "-g" is not specified, so the bug seems to be in the > debug information that are added to the classfile. > > javac -g --enable-preview --source 22 GUI.java > > Here is a simpler reproducer > > > import java.util.function.Consumer; > > public class GUI { > public static void main(String[] args) { > Consumer op = _ -> {}; > } > } > > > javap shows the issue, the LocalVariableTable is generated with the name "" > > private static void lambda$main$0(java.lang.String); > descriptor: (Ljava/lang/String;)V > flags: (0x100a) ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC > Code: > stack=0, locals=1, args_size=1 > 0: return > LineNumberTable: > line 5: 0 > LocalVariableTable: > Start Length Slot Name Signature > 0 1 0 Ljava/lang/String; > > The JVM spec 4.7.13 said > " > name_index > > The value of the name_index item must be a valid index into the > constant_pool table. The constant_pool entry at that index must contain a > CONSTANT_Utf8_info structure representing a valid unqualified name > denoting a local variable (?4.2.2 > > ). > > " > > And 4.2.2 said that the string must have at least one code point, so "" is > an invalid name, rightly rejected by the VM (the error message is just not > great, it's not about a field but a local variable name, here a parameter > inside the LocalVariableTable). > > So it's a bug in the compiler, I see two ways to fix it, either do not > generate a line in the LocalVariableTable if the parameter is unamed or use > "_" instead. > > regards, > R?mi > > ------------------------------ > > *From: *"David Alayachew" > *To: *"amber-dev" > *Sent: *Sunday, August 6, 2023 4:31:54 PM > *Subject: *Re: Illegal field name when trying to compile with a > javax.swing.Action > > Also, here is my version info. > > > $ java --version > openjdk 21-ea 2023-09-19 > OpenJDK Runtime Environment (build 21-ea+31-2444) > OpenJDK 64-Bit Server VM (build 21-ea+31-2444, mixed mode, sharing) > > > $ javac --version > javac 21-ea > > > > On Sun, Aug 6, 2023 at 7:31?PM David Alayachew > wrote: > >> Hello Amber Dev Team, >> >> I ran into a problem that I am not sure what the cause is. It only seems >> to occur when I am using unnamed variables. >> >> >> Here are the commands that I am using, as well as their outputs. >> >> >> $ javac -g -Xlint:all,-preview,-serial -Xdiags:verbose --enable-preview >> --source 21 GUI.java >> Note: GUI.java uses preview features of Java SE 21. >> Note: Recompile with -Xlint:preview for details. >> >> >> $ java --enable-preview GUI >> Error: LinkageError occurred while loading main class GUI >> java.lang.ClassFormatError: Illegal field name "" in class GUI >> >> And here is the file that I am using. >> >> >> import javax.swing.JPanel; >> import javax.swing.JLabel; >> import javax.swing.JButton; >> import java.util.function.BiFunction; >> >> public class GUI >> { >> >> public static void main(String[] args) >> { >> >> new GUI(null, null); >> >> } >> >> public GUI(final Object characterType, final Object icon) >> { >> >> } >> >> private Object createConstraintPanel() >> { >> >> final JPanel constraintPanel = new JPanel(); >> final JButton button = new JButton(); >> >> CREATE_INPUT_SANITIZATION: >> { >> >> BUTTON_ACTION_LISTENER: >> { >> >> button >> .addActionListener >> ( >> _ -> >> { >> >> final BiFunction >> createLabel = >> (text, width) -> >> { >> >> return null; >> >> } >> ; >> >> final JButton remove = new JButton(); >> remove >> .addActionListener >> ( >> _ -> >> { >> >> >> } >> ); >> >> } >> ) >> ; >> >> } >> >> } >> >> return constraintPanel; >> >> } >> >> } >> >> Technically, this issue also occurs if even 1 of the 2 unnamed variables >> is turned into a real variable. But regardless, the point is, this fails at >> run time. >> >> Please let me know if there is anything I am missing. >> >> Thank you for your time and help! >> David Alayachew >> >> >> On Tue, Jul 18, 2023 at 1:54?AM David Alayachew >> wrote: >> >>> Ok, ty for the heads up. >>> >>> On Tue, Jul 18, 2023 at 1:18?AM - wrote: >>> >>>> Hi David, >>>> Please do not ask for technical support in the development mailing >>>> list. There's no proof that this issue is with the core libraries instead >>>> of the Java compiler or another component. >>>> I have already downloaded your zip, compiled the 4 files with JDK 22 >>>> (my local dev build for another unrelated patch) javac --enable-preview >>>> -release 22 *.java and java --enable-preview ToDoList, which just shows up >>>> a UI without any crash. Without enable-preview, yoru code does not compile >>>> at all for the usage of _ as an identifier. >>>> >>>> This is most likely a problem with the compiler you are using; you have >>>> a gpj file, which probably means you are using jGrasp. Please report this >>>> issue to the relevant parties (i.e. the 3rd-party IDE or whatever supports >>>> using _ as identifer without --enable-preview) instead. >>>> >>>> Chen Liang >>>> >>>> On Tue, Jul 18, 2023 at 11:43?AM David Alayachew < >>>> davidalayachew at gmail.com> wrote: >>>> >>>>> Wait, nevermind. Don't ignore. I was able to recreate this issue on >>>>> the command line using the abovementioned JDK. Could someone come back and >>>>> take a look at this please? >>>>> >>>>> Sorry for jerking everyone around here. I have multiple JDK's and got >>>>> mixed up on which one I was using. >>>>> >>>>> On Sun, Jul 16, 2023 at 2:26?AM David Alayachew < >>>>> davidalayachew at gmail.com> wrote: >>>>> >>>>>> Hmmmm, this one might actually be IDE specific. Please ignore. >>>>>> >>>>> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidalayachew at gmail.com Tue Aug 8 20:28:55 2023 From: davidalayachew at gmail.com (David Alayachew) Date: Tue, 8 Aug 2023 16:28:55 -0400 Subject: Illegal field name when trying to compile with a javax.swing.Action In-Reply-To: References: <1734640837.9801388.1691435449049.JavaMail.zimbra@univ-eiffel.fr> Message-ID: I think you are correct. Regardless, another example to test against is good to have. On Tue, Aug 8, 2023 at 1:59?PM Florent Guillaume < florent.guillaume at gmail.com> wrote: > Hi, > > I believe this is https://github.com/openjdk/jdk/pull/15083 > > Florent > > On Mon, Aug 7, 2023 at 9:12?PM Remi Forax wrote: > >> Hi David, >> thanks for the bug report. >> >> I was able to reproduce the issue with the latest early acces of 22, >> There is no issue if "-g" is not specified, so the bug seems to be in >> the debug information that are added to the classfile. >> >> javac -g --enable-preview --source 22 GUI.java >> >> Here is a simpler reproducer >> >> >> import java.util.function.Consumer; >> >> public class GUI { >> public static void main(String[] args) { >> Consumer op = _ -> {}; >> } >> } >> >> >> javap shows the issue, the LocalVariableTable is generated with the name >> "" >> >> private static void lambda$main$0(java.lang.String); >> descriptor: (Ljava/lang/String;)V >> flags: (0x100a) ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC >> Code: >> stack=0, locals=1, args_size=1 >> 0: return >> LineNumberTable: >> line 5: 0 >> LocalVariableTable: >> Start Length Slot Name Signature >> 0 1 0 Ljava/lang/String; >> >> The JVM spec 4.7.13 said >> " >> name_index >> >> The value of the name_index item must be a valid index into the >> constant_pool table. The constant_pool entry at that index must contain >> a CONSTANT_Utf8_info structure representing a valid unqualified name >> denoting a local variable (?4.2.2 >> >> ). >> >> " >> >> And 4.2.2 said that the string must have at least one code point, so "" >> is an invalid name, rightly rejected by the VM (the error message is just >> not great, it's not about a field but a local variable name, here a >> parameter inside the LocalVariableTable). >> >> So it's a bug in the compiler, I see two ways to fix it, either do not >> generate a line in the LocalVariableTable if the parameter is unamed or use >> "_" instead. >> >> regards, >> R?mi >> >> ------------------------------ >> >> *From: *"David Alayachew" >> *To: *"amber-dev" >> *Sent: *Sunday, August 6, 2023 4:31:54 PM >> *Subject: *Re: Illegal field name when trying to compile with a >> javax.swing.Action >> >> Also, here is my version info. >> >> >> $ java --version >> openjdk 21-ea 2023-09-19 >> OpenJDK Runtime Environment (build 21-ea+31-2444) >> OpenJDK 64-Bit Server VM (build 21-ea+31-2444, mixed mode, sharing) >> >> >> $ javac --version >> javac 21-ea >> >> >> >> On Sun, Aug 6, 2023 at 7:31?PM David Alayachew >> wrote: >> >>> Hello Amber Dev Team, >>> >>> I ran into a problem that I am not sure what the cause is. It only seems >>> to occur when I am using unnamed variables. >>> >>> >>> Here are the commands that I am using, as well as their outputs. >>> >>> >>> $ javac -g -Xlint:all,-preview,-serial -Xdiags:verbose --enable-preview >>> --source 21 GUI.java >>> Note: GUI.java uses preview features of Java SE 21. >>> Note: Recompile with -Xlint:preview for details. >>> >>> >>> $ java --enable-preview GUI >>> Error: LinkageError occurred while loading main class GUI >>> java.lang.ClassFormatError: Illegal field name "" in class GUI >>> >>> And here is the file that I am using. >>> >>> >>> import javax.swing.JPanel; >>> import javax.swing.JLabel; >>> import javax.swing.JButton; >>> import java.util.function.BiFunction; >>> >>> public class GUI >>> { >>> >>> public static void main(String[] args) >>> { >>> >>> new GUI(null, null); >>> >>> } >>> >>> public GUI(final Object characterType, final Object icon) >>> { >>> >>> } >>> >>> private Object createConstraintPanel() >>> { >>> >>> final JPanel constraintPanel = new JPanel(); >>> final JButton button = new JButton(); >>> >>> CREATE_INPUT_SANITIZATION: >>> { >>> >>> BUTTON_ACTION_LISTENER: >>> { >>> >>> button >>> .addActionListener >>> ( >>> _ -> >>> { >>> >>> final BiFunction >>> createLabel = >>> (text, width) -> >>> { >>> >>> return null; >>> >>> } >>> ; >>> >>> final JButton remove = new JButton(); >>> remove >>> .addActionListener >>> ( >>> _ -> >>> { >>> >>> >>> } >>> ); >>> >>> } >>> ) >>> ; >>> >>> } >>> >>> } >>> >>> return constraintPanel; >>> >>> } >>> >>> } >>> >>> Technically, this issue also occurs if even 1 of the 2 unnamed variables >>> is turned into a real variable. But regardless, the point is, this fails at >>> run time. >>> >>> Please let me know if there is anything I am missing. >>> >>> Thank you for your time and help! >>> David Alayachew >>> >>> >>> On Tue, Jul 18, 2023 at 1:54?AM David Alayachew < >>> davidalayachew at gmail.com> wrote: >>> >>>> Ok, ty for the heads up. >>>> >>>> On Tue, Jul 18, 2023 at 1:18?AM - wrote: >>>> >>>>> Hi David, >>>>> Please do not ask for technical support in the development mailing >>>>> list. There's no proof that this issue is with the core libraries instead >>>>> of the Java compiler or another component. >>>>> I have already downloaded your zip, compiled the 4 files with JDK 22 >>>>> (my local dev build for another unrelated patch) javac --enable-preview >>>>> -release 22 *.java and java --enable-preview ToDoList, which just shows up >>>>> a UI without any crash. Without enable-preview, yoru code does not compile >>>>> at all for the usage of _ as an identifier. >>>>> >>>>> This is most likely a problem with the compiler you are using; you >>>>> have a gpj file, which probably means you are using jGrasp. Please report >>>>> this issue to the relevant parties (i.e. the 3rd-party IDE or whatever >>>>> supports using _ as identifer without --enable-preview) instead. >>>>> >>>>> Chen Liang >>>>> >>>>> On Tue, Jul 18, 2023 at 11:43?AM David Alayachew < >>>>> davidalayachew at gmail.com> wrote: >>>>> >>>>>> Wait, nevermind. Don't ignore. I was able to recreate this issue on >>>>>> the command line using the abovementioned JDK. Could someone come back and >>>>>> take a look at this please? >>>>>> >>>>>> Sorry for jerking everyone around here. I have multiple JDK's and got >>>>>> mixed up on which one I was using. >>>>>> >>>>>> On Sun, Jul 16, 2023 at 2:26?AM David Alayachew < >>>>>> davidalayachew at gmail.com> wrote: >>>>>> >>>>>>> Hmmmm, this one might actually be IDE specific. Please ignore. >>>>>>> >>>>>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: