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

The result of the combine method of SettingsControl is not used

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2
    • 24
    • 8, 11, 17, 21, 22
    • hotspot
    • None
    • jfr
    • b13

    Description

      When settings are set in multiple recordings, SettingsControl combine those settings using the combine method. The result is then assumed to be used as the argument of the setValue method.

      In practice, however, the return value of the combine method is not used, and the argument of the setValue method is always null.

      Sample code is followings,

      ```
      import jdk.jfr.Event;
      import jdk.jfr.Name;
      import jdk.jfr.Recording;
      import jdk.jfr.SettingControl;
      import jdk.jfr.SettingDefinition;

      import java.util.ArrayList;
      import java.util.List;
      import java.util.Set;
      import java.util.stream.Collectors;

      public class Main {
          public static void main(String[] args) {
              try(Recording r1 = new Recording(); Recording r2 = new Recording()){
                  r1.enable("SettingControlEvent").with("hostFilter", "A");
                  r1.start();

                  r2.enable("SettingControlEvent").with("hostFilter", "B");
                  r2.start();

                  Event e = new SettingControlEvent("A");
                  e.begin();
                  e.end();
                  if (e.shouldCommit()) {
                      System.out.println("Event will be committed");
                      e.commit();
                  } else {
                      System.out.println("Event did not commit");
                  }
              }
          }

          @Name("SettingControlEvent")
          static class SettingControlEvent extends Event {

              public SettingControlEvent(String host) {
                  this.host = host;
              }

              public final String host;

              @Name("hostFilter")
              @SettingDefinition
              protected boolean hostFilter(MyEqualControl control) {
                  return control.matches(host);
              }
          }

          static class MyEqualControl extends SettingControl {

              private List<String> hosts = new ArrayList<>();

              @Override
              public void setValue(String value) {
                  System.out.println("MyEqualControl setValue : " + value);
                  this.hosts.add(value);
              }

              @Override
              public String combine(Set<String> values) {
                  return values.stream().collect(Collectors.joining(","));
              }

              @Override
              public String getValue() {
                  if (hosts == null) {
                      return "";
                  }
                  return hosts.stream().collect(Collectors.joining(","));
              }

              public boolean matches(String value) {
                  System.out.println("value is " + value + ", hosts are " + this.hosts.toString());
                  return this.hosts.contains(value);
              }
          }
      }
      ```

      sout
      ```
      MyEqualControl setValue :
      MyEqualControl setValue : null
      value is A, hosts are [, null]
      Event did not commit
      MyEqualControl setValue : A
      ```

      Attachments

        Issue Links

          Activity

            People

              cito Chihiro Ito
              cito Chihiro Ito
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: