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

JFR: Names should only be valid Java identifiers

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 18
    • None
    • hotspot
    • None
    • jfr
    • b16

      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.

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

              Created:
              Updated:
              Resolved: