QDox
  1. QDox
  2. QDOX-59

Provide consistent ordering for JavaClass.getBeanProperties

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.6
    • Component/s: Java API
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Consistent ordering ( for example alphabetic ) is important for
      unit testing by generama testcases.
      current HashMaps do not provide consistent ordering between different java vesrsions - this leads to failing builds.

      Possible solution would be to change HashMaps to TreeMaps -> alphabetical ordering.

      While it is possible to perform sorting on client side ( in plugins etc. ) , this will be less work to fix it in qdox...

      Patches to follow if accepted

      1. qdox.patch
        0.4 kB
        Konstantin Pribluda

        Activity

        Hide
        Mike Williams added a comment -

        I agree, ordering of collections should be consistent across JDKs, and across runs of QDox. IMHO source elements should be listed in the order they were declared in the original source.

        I thought this was largely the case already, actually; in most cases, we maintain ordered lists of elements, append to the end while parsing the source, and make them available as arrays in the API.

        Obviously, there must be cases where this is not true (or you wouldn't have raised this issue). Konstanstin, can you provided specific examples of calls that return Collections/Maps with inconsistent ordering? Thanks.

        Show
        Mike Williams added a comment - I agree, ordering of collections should be consistent across JDKs, and across runs of QDox. IMHO source elements should be listed in the order they were declared in the original source. I thought this was largely the case already, actually; in most cases, we maintain ordered lists of elements, append to the end while parsing the source, and make them available as arrays in the API. Obviously, there must be cases where this is not true (or you wouldn't have raised this issue). Konstanstin, can you provided specific examples of calls that return Collections/Maps with inconsistent ordering? Thanks.
        Hide
        Konstantin Pribluda added a comment -

        for example JavaClass.getBeanPropertyMap()
        gathers them into HashMap, and then converts
        values() to array - using threeMap instead helps

        I' attaching small patch for just one change.

        Show
        Konstantin Pribluda added a comment - for example JavaClass.getBeanPropertyMap() gathers them into HashMap, and then converts values() to array - using threeMap instead helps I' attaching small patch for just one change.
        Hide
        Konstantin Pribluda added a comment -

        just small patch for JavaClass

        Show
        Konstantin Pribluda added a comment - just small patch for JavaClass
        Konstantin Pribluda made changes -
        Field Original Value New Value
        Attachment qdox.patch [ 12433 ]
        Mike Williams made changes -
        Assignee Mike Williams [ mdub ]
        Hide
        Mike Williams added a comment -

        Thanks Konstantin; I've re-titled the issue. I'll apply your s/HashMap/TreeMap/ patch as a quick fix.

        But the behaviour may change again, as longer-term, I'd prefer the ordering as declared in the source to be preserved.

        Show
        Mike Williams added a comment - Thanks Konstantin; I've re-titled the issue. I'll apply your s/HashMap/TreeMap/ patch as a quick fix. But the behaviour may change again, as longer-term, I'd prefer the ordering as declared in the source to be preserved.
        Mike Williams made changes -
        Summary Provide consistent ordering on class propeties , methods and members Provide consistent ordering for JavaClass.getBeanProperties
        Affects Version/s 1.5 [ 10650 ]
        Affects Version/s 1.6 [ 10814 ]
        Fix Version/s 1.6 [ 10814 ]
        Hide
        Konstantin Pribluda added a comment -

        well, this is not only JavaClass, but everywhere else...

        Show
        Konstantin Pribluda added a comment - well, this is not only JavaClass, but everywhere else...
        Hide
        Mike Williams added a comment -

        Sorry; there are plenty of Collections that do have consistent ordering, so "everywhere else" doesn't help me much. Can you be more specific about where ordering is inconsistent?

        • Bean properties, we've already covered.
        • Looks like named-parameters of tags might have the same problem?
        • Anywhere else??

        Specific use-cases would be appreciated. JUnit test-cases would be even better!

        By the way, why is consistent ordering important for Generama test-cases? Can you provide an example of a test that fails?

        Show
        Mike Williams added a comment - Sorry; there are plenty of Collections that do have consistent ordering, so "everywhere else" doesn't help me much. Can you be more specific about where ordering is inconsistent? Bean properties, we've already covered. Looks like named-parameters of tags might have the same problem? Anywhere else?? Specific use-cases would be appreciated. JUnit test-cases would be even better! By the way, why is consistent ordering important for Generama test-cases? Can you provide an example of a test that fails?
        Hide
        Konstantin Pribluda added a comment -

        generama test cases use ast parser to compare generated java files.
        well, it's not generama which uses them, of course it's unit test
        for xdoclet-2 plugins which happen to generate java code.

        There is manually written java source, which serves as "correct"
        code, and it is compared with generated one.

        If I iterate over properties inside some method - test fails.

        -------%<---------
        setFoo("blurge");
        setBar("bang");
        -------%<---------

        is not equal to:

        -------%<---------
        setBar("bang");
        setFoo("blurge");
        -------%<---------

        I will raise dependency on xdoclet plugins and look where similar problem may arise.

        Show
        Konstantin Pribluda added a comment - generama test cases use ast parser to compare generated java files. well, it's not generama which uses them, of course it's unit test for xdoclet-2 plugins which happen to generate java code. There is manually written java source, which serves as "correct" code, and it is compared with generated one. If I iterate over properties inside some method - test fails. ------- %< --------- setFoo("blurge"); setBar("bang"); ------- %< --------- is not equal to: ------- %< --------- setBar("bang"); setFoo("blurge"); ------- %< --------- I will raise dependency on xdoclet plugins and look where similar problem may arise.
        Mike Williams made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Mike Williams added a comment -

        Okay, I'm convinced Thanks.

        I've switched tag named-parameters from HashMap to TreeMap, which will hopefully fix your problem for now.

        Stay tuned, though, as I intend to change this again: order will be based on relative position in the source, rather than alphabetical.

        Show
        Mike Williams added a comment - Okay, I'm convinced Thanks. I've switched tag named-parameters from HashMap to TreeMap, which will hopefully fix your problem for now. Stay tuned, though, as I intend to change this again: order will be based on relative position in the source, rather than alphabetical.
        Hide
        Konstantin Pribluda added a comment -

        well, if you do it after 1.6 ( on 1.7 ) everything would be fine,
        unless some unlucky soul raises dependency on generama / xdoclet-2 / xdoclet plugins

        I will certainly alerted on the spot by failed unit tests...

        Show
        Konstantin Pribluda added a comment - well, if you do it after 1.6 ( on 1.7 ) everything would be fine, unless some unlucky soul raises dependency on generama / xdoclet-2 / xdoclet plugins I will certainly alerted on the spot by failed unit tests...
        Hide
        Mike Williams added a comment -

        Done; I added a dumb Map implementation that returns things in insertion order.

        Konstantin, please let me know if problems remain.

        Show
        Mike Williams added a comment - Done; I added a dumb Map implementation that returns things in insertion order. Konstantin, please let me know if problems remain.
        Mike Williams made changes -
        Resolution Fixed [ 1 ]
        Status In Progress [ 3 ] Resolved [ 5 ]
        Hide
        Mike Williams added a comment -

        No complaints. Case closed.

        Show
        Mike Williams added a comment - No complaints. Case closed.
        Mike Williams made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Mike Williams
            Reporter:
            Konstantin Pribluda
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: