<!-- 
RSS generated by JIRA (8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d) at Wed Feb 07 20:09:29 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>OpenDaylight JIRA</title>
    <link>https://jira.opendaylight.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>8.20.10</version>
        <build-number>820010</build-number>
        <build-date>22-06-2022</build-date>
    </build-info>


<item>
            <title>[MDSAL-309] V1 codegen generates enum constants that are not valid Java identifiers</title>
                <link>https://jira.opendaylight.org/browse/MDSAL-309</link>
                <project id="10137" key="MDSAL">mdsal</project>
                    <description>&lt;p&gt;If enum value is not valid Java identifier, e.g.:&lt;/p&gt;

&lt;p&gt;&#160;&#160;&#160;&#160;&#160; type enumeration {&lt;br/&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; enum &apos;*&apos; &lt;/p&gt;
{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; description
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &quot;Any source address.&quot;;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
&lt;p&gt;&#160;&#160;&#160;&#160;&#160; }&lt;/p&gt;

&lt;p&gt;V1 code generator produces invalid enum constant identifier:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;public class Ipv4MulticastSourceAddress&lt;br/&gt;
&#160;implements Serializable {&lt;br/&gt;
&#160;&#160;&#160; private static final long serialVersionUID = -1734346858985024066L;&lt;br/&gt;
&#160;&#160;&#160; public enum Enumeration {&lt;br/&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; /**&lt;br/&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * Any source address.&lt;br/&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; *&lt;br/&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; */&lt;br/&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;b&gt;(0, &quot;&lt;/b&gt;&quot;)&lt;br/&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; ;&lt;br/&gt;
&#160;&#160; &lt;span class=&quot;error&quot;&gt;&amp;#91;...&amp;#93;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;hence compilation fails.&lt;/p&gt;</description>
                <environment></environment>
        <key id="29169">MDSAL-309</key>
            <summary>V1 codegen generates enum constants that are not valid Java identifiers</summary>
                <type id="10104" iconUrl="https://jira.opendaylight.org/secure/viewavatar?size=xsmall&amp;avatarId=10303&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.opendaylight.org/images/icons/priorities/major.svg">Medium</priority>
                        <status id="5" iconUrl="https://jira.opendaylight.org/images/icons/statuses/resolved.png" description="A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.">Resolved</status>
                    <statusCategory id="3" key="done" colorName="green"/>
                                    <resolution id="10000">Done</resolution>
                                        <assignee username="rovarga">Robert Varga</assignee>
                                    <reporter username="mgradzki">Marek Gradzki</reporter>
                        <labels>
                    </labels>
                <created>Thu, 8 Feb 2018 13:22:38 +0000</created>
                <updated>Thu, 5 Apr 2018 09:11:00 +0000</updated>
                            <resolved>Fri, 23 Mar 2018 11:09:10 +0000</resolved>
                                    <version>Nitrogen SR1</version>
                                    <fixVersion>Carbon SR4</fixVersion>
                    <fixVersion>Oxygen SR1</fixVersion>
                    <fixVersion>Fluorine</fixVersion>
                    <fixVersion>Nitrogen SR3</fixVersion>
                                    <component>Binding codegen</component>
                        <due></due>
                            <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="60989" author="mgradzki@cisco.com" created="Thu, 8 Feb 2018 14:10:24 +0000"  >&lt;p&gt;The issue is related to ietf-routing-types@2017-02-27 so simplest fix would be to&lt;/p&gt;

&lt;p&gt;transform characters that are not Java IdentifierChars to UNICODE names (Character.getName) + underscore separators.&lt;/p&gt;

&lt;p&gt;Solution is backward compatible (in YANG-&amp;gt;Java direction, not sure if other direction is relevant),&lt;/p&gt;

&lt;p&gt;but such mapping might produce collisions (e.g. &quot;*&quot; and &quot;&lt;em&gt;ASTERIX&lt;/em&gt;&quot;).&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Solution 2:&lt;/p&gt;

&lt;p&gt;Replace all underscores in the enum name to pars of underscores (required to prevent collisions as in S1),&lt;/p&gt;

&lt;p&gt;then replace non-java IdentifierChars to UNICODE names + underscore separators.&lt;/p&gt;

&lt;p&gt;Such mapping is not backwards compatible, but it&apos;s injective (probably 1-1).&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="61561" author="rovarga" created="Thu, 8 Mar 2018 16:28:07 +0000"  >&lt;p&gt;RFC7950 specifies enum statement argument as: &lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;   The &quot;enum&quot; statement, which is a substatement to the &quot;type&quot;
   statement, MUST be present if the type is &quot;enumeration&quot;.  It is
   repeatedly used to specify each assigned name of an enumeration type.
   It takes as an argument a string that is the assigned name.  The
   string MUST NOT be zero-length and MUST NOT have any leading or
   trailing whitespace characters (any Unicode character with the
   &quot;White_Space&quot; property).  The use of Unicode control codes SHOULD be
   avoided.&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Which means we need to handle any old Unicode string. Generated name has to be a valid Java identifier, as per &lt;a href=&quot;https://docs.oracle.com/javase/specs/jls/se9/html/jls-3.html#jls-3.8&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.oracle.com/javase/specs/jls/se9/html/jls-3.html#jls-3.8&lt;/a&gt;, which specifies it as:&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;A &quot;Java letter&quot; is a character for which the method Character.isJavaIdentifierStart(int) returns true.

A &quot;Java letter-or-digit&quot; is a character for which the method Character.isJavaIdentifierPart(int) returns true.

The &quot;Java letters&quot; include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII dollar sign ($, or \u0024) and underscore (_, or \u005f). The dollar sign should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems. The underscore may be used in identifiers formed of two or more characters, but it cannot be used as a one-character identifier due to being a keyword.

The &quot;Java digits&quot; include the ASCII digits 0-9 (\u0030-\u0039).

Letters and digits may be drawn from the entire Unicode character set, which supports most writing scripts in use in the world today, including the large sets for Chinese, Japanese, and Korean. This allows programmers to use identifiers in their programs that are written in their native languages.&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;YANG/Java mapping in this case needs to be at least an injection, so codegen works in a non-conflicting manner. We can work out the reverse assignment based on value (and sanity-check with the same function).&lt;/p&gt;

&lt;p&gt;I have (inexactly) examined the currently-public corpus of YANG models from github, which shows 16432 unique strings being used, some of which are fun (single-letter, ?, *). The corpus is attached to this issue.&lt;/p&gt;</comment>
                            <comment id="61568" author="rovarga" created="Thu, 8 Mar 2018 17:07:19 +0000"  >&lt;p&gt;Based on this data and the expectation we will be allowed to break the spec in Fluorine, I would propose actually having the mapping function discontinuous, with separate mapping rules based on the contents of the entire string. Extracted corpus shows that &apos;$&apos; is not used anywhere, which makes it a good escape character from JLS perspective (use in generated source code, can be start of an identifier) and observed corpus (it does not show a need to escape it).&lt;/p&gt;

&lt;p&gt;Hence the rules would be the following:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;if the string is a valid java identifier and does not contain &apos;$&apos;, use it as-is&lt;/li&gt;
	&lt;li&gt;otherwise prefix it with &apos;$&apos; and replace any invalid character with &apos;$XXX$&apos;, where XXX is hex-encoded unicode codepoint (including plane, stripping leading zeroes)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;This would break the users thoroughly, I am afraid &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.opendaylight.org/images/icons/emoticons/sad.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;As a mitigation, we can perhaps consider enums within the enumeration to decide how to map members and reflect that in the enumeration class name... Perhaps use current mapping schema when the result is known to work and use a trailing &apos;$&apos; when we know the enums are a mess and we are using the above schema...&lt;/p&gt;

&lt;p&gt;Any thoughts on this?&lt;/p&gt;</comment>
                            <comment id="61595" author="mgradzki@cisco.com" created="Fri, 9 Mar 2018 07:46:25 +0000"  >&lt;p&gt;Using current mapping schema when result is Java identifier, otherwise the one you propose looks backward compatible to me.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Such mapping is not invertible unless we know which schema was used.&lt;/p&gt;

&lt;p&gt;AFAIR Enumerations class is not generated if enumeration is defined using typedef, so&lt;/p&gt;

&lt;p&gt;perhaps we should consider using getter instead of class name. That would not break current users.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;But not sure why we can&apos;t use yang names of enums instead. They are already present in the generated code.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="61610" author="rovarga" created="Fri, 9 Mar 2018 17:35:53 +0000"  >&lt;p&gt;As it turns out we do not need to mark the enumeration name at all. The only place that needs to reconcile Binding-&amp;gt;Yang names (and vice-versa) is the binding codec, which has both the class and EnumTypeDefinition already available &#8211; hence pairing the two is a rather trivial matter.&lt;/p&gt;

&lt;p&gt;It would be possible to reconstruct this even without the help of schema, as the class itself captures and exposes YANG names, except it is not captured in a common contract, so we&apos;d have to resort to reflection. I have filed &lt;a href=&quot;https://jira.opendaylight.org/browse/MDSAL-317&quot; title=&quot;Generated enumerations should be implementing a yang-binding Enumeration interface&quot; class=&quot;issue-link&quot; data-issue-key=&quot;MDSAL-317&quot;&gt;&lt;del&gt;MDSAL-317&lt;/del&gt;&lt;/a&gt; to track that improvement.&lt;/p&gt;</comment>
                            <comment id="61611" author="rovarga" created="Fri, 9 Mar 2018 17:46:32 +0000"  >&lt;p&gt;Fluorine: &lt;a href=&quot;https://git.opendaylight.org/gerrit/69317&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://git.opendaylight.org/gerrit/69317&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="61649" author="rovarga" created="Sat, 10 Mar 2018 09:23:26 +0000"  >&lt;p&gt;Since the fix is backwards-compatible, it will be applied to all currently-supported streams.&lt;/p&gt;</comment>
                            <comment id="61651" author="rovarga" created="Sat, 10 Mar 2018 11:52:54 +0000"  >&lt;p&gt;Oxygen: &lt;a href=&quot;https://git.opendaylight.org/gerrit/69334&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://git.opendaylight.org/gerrit/69334&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nitrogen: &lt;a href=&quot;https://git.opendaylight.org/gerrit/69336&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://git.opendaylight.org/gerrit/69336&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Carbon: &lt;a href=&quot;https://git.opendaylight.org/gerrit/69338&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://git.opendaylight.org/gerrit/69338&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10000">
                    <name>Blocks</name>
                                            <outwardlinks description="blocks">
                                        <issuelink>
            <issuekey id="29393">MDSAL-317</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10002">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="27030">MDSAL-208</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="29603">MDSAL-333</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10003">
                    <name>Relates</name>
                                            <outwardlinks description="relates to">
                                        <issuelink>
            <issuekey id="27091">MDSAL-269</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="14460" name="extracted-enums.txt.xz" size="67876" author="rovarga" created="Thu, 8 Mar 2018 16:29:45 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                            <customfield id="customfield_11400" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10000" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0|i03a3r:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                </customfields>
    </item>
</channel>
</rss>