Illegal field name when trying to compile with a javax.swing.Action
David Alayachew
davidalayachew at gmail.com
Tue Aug 8 20:28:55 UTC 2023
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 <forax at univ-mlv.fr> 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<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 (§4.2.2
>> <https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-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" <davidalayachew at gmail.com>
>> *To: *"amber-dev" <amber-dev at openjdk.org>
>> *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 <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<String, Integer, JLabel>
>>> 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 - <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 <
>>>>> 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: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230808/d01ae52f/attachment-0001.htm>
More information about the amber-dev
mailing list