Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6388374

MXBean spec should mention recursive data structures

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • core-svc
    • b91
    • generic
    • generic
    • Verified

      The MXBean spec does not explicitly say that recursive data structures such as the following cannot be mapped into Open Types:

      public class Node {
          @PropertyNames({"adjacent"})
          public Node(Set<Node> adjacent) {
              this.adjacent = adjacent;
          }
          public Set<Node> getAdjacent() {
              return adjacent;
          }
          private final Set<Node> adjacent;
      }

      But they can't, basically because recursive data structures imply cycles, and immutable types such as CompositeType and CompositeData can't be used to build cycles.

      The spec should explicitly say that recursive data structures are forbidden, and suggest workarounds. Typically, a workaround is to add a level of indirection, like this:

      public class Node {
          @PropertyNames({"name", "adjacent"})
          public Node(String name, Set<String> adjacent) {
              this.name = name;
              this.adjacent = adjacent;
          }
          ...
      }
      public class Graph {
          @PropertyNames({"nodeNames"})
          public Graph(Map<String, Node> nodeNames) {
              ...
          }
          ...
      }

            emcmanus Eamonn McManus
            emcmanus Eamonn McManus
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: