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

JFR: Names should only be valid Java identifiers

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 18
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
      jfr
    • Resolved In Build:
      b16

      Description

      Today, you can set a custom name to a field using the @Name annotation, or by passing the name to the ValueDescriptor class when creating a dynamic event. For example:

      class Transaction extends Event {
         @Name("foo")"
         int _lousy_field_name;
      }
      var e = new Transaction();
      ...

      var fields = new ArrayList<ValueDescriptor>();
      fields.add(new ValueDescriptor(int.class, "foo"));
      var f = EventFactory.create("Transaction". List.of(), fields);
      var e = f.newEvent();
      ...

      The ValueDescriptor constructor states that the name must be valid, but an IllegalArgumentException is not thrown when the object is created.
       The @Name annotation states that the name must be a valid Java identifier, but it's not enforced when the event class is registered.

      This can be problematic if trying to reconstruct events as classes, for example in a parser, if class and field names are not valid. Furthermore, if the fields are used to output data, for example a CSV file, for a plotting utility it will break if spaces, tabs or newlines can be used. The expectations is that field, event and settings names are valid.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              egahlin Erik Gahlin
              Reporter:
              egahlin Erik Gahlin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: