Skip to content

XML: Issue with $ sign in Java identifiers #8617

@Stewori

Description

@Stewori

Describe the bug
Processing Java code

public class Test {
    public int someField$;
    public void some$method() {}
}

results in the following xml snippet:

<memberdef kind="variable" id="classTest_1a815731dc2a896b452259b4c63e37ce4c" prot="public" static="no" mutable="no">
        <type>int</type>
        <definition>int Test.someField</definition>
        <argsstring></argsstring>
        <name>someField</name>
        ...
        <location file="Test.java" line="3" column="16" bodyfile="Test.java" bodystart="3" bodyend="-1"/>
      </memberdef>
      </sectiondef>
      <sectiondef kind="public-func">
      <memberdef kind="function" id="classTest_1ae5eaada7e3b388b5e319240398670c34" prot="public" static="no" const="no" explicit="no" inline="yes" virt="non-virtual">
        <type>void some</type>
        <definition>void some Test.$method</definition>
        <argsstring>()</argsstring>
        <name>$method</name>
        ...
        <location file="Test.java" line="4" column="21" bodyfile="Test.java" bodystart="4" bodyend="4"/>
      </memberdef>

Please note that the $ sign is a legal character for Java identifiers.
https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html#jls-3.8

The issue also applies to $ occurring in class/interface/etc names.
Even worse: If one has two classes Test and Test$ Doxygen will combine them into one xml file. It contains both of their members as if they were in one class. I did not even test what happens in case of member name collisions then.

Expected behavior
I expect that for Java identifiers, the $ sign is treated like any other legal character.
The resulting code snippet should be

<memberdef kind="variable" id="classTest_1a815731dc2a896b452259b4c63e37ce4c" prot="public" static="no" mutable="no">
        <type>int</type>
        <definition>int Test.someField$</definition>
        <argsstring></argsstring>
        <name>someField$</name>
        ...
        <location file="Test.java" line="3" column="16" bodyfile="Test.java" bodystart="3" bodyend="-1"/>
      </memberdef>
      </sectiondef>
      <sectiondef kind="public-func">
      <memberdef kind="function" id="classTest_1ae5eaada7e3b388b5e319240398670c34" prot="public" static="no" const="no" explicit="no" inline="yes" virt="non-virtual">
        <type>void</type>
        <definition>void Test.some$method</definition>
        <argsstring>()</argsstring>
        <name>some$method</name>
        ...
        <location file="Test.java" line="4" column="21" bodyfile="Test.java" bodystart="4" bodyend="4"/>
      </memberdef>

To Reproduce
Find a Java file and doxygen config attached. The issue is demonstrated like mentioned above.
After running doxygen on the example, the files in the subfolder xml contain the snippet shown above.
issue_dollar.zip

Version
Tested with doxygen clone from 2021-05-26:

/blah/doxygen/build/bin/doxygen -v
1.9.2 (da0a6b42c349bc06b2804a4b0e8f55c7690f5cf9*)

lsb_release -a:

LSB Version:	core-9.20160110ubuntu0.2-amd64:core-9.20160110ubuntu0.2-noarch:security-9.20160110ubuntu0.2-amd64:security-9.20160110ubuntu0.2-noarch
Distributor ID:	LinuxMint
Description:	Linux Mint 18 Sarah
Release:	18
Codename:	sarah

Additional context
I know the dollar sign is rarely used and not recommended in Java identifiers. However, in large code bases it occurs from time to time. This issue makes the doc unreliable and messy wherever a $ occurs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Javaenhancementa request to enhance doxygen, not a bug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions