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

JFR: Names should only be valid Java identifiers

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P3
    • Resolution: Fixed
    • None
    • 18
    • hotspot
    • None
    • jfr
    • 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

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

              Dates

                Created:
                Updated:
                Resolved: