Skip to content

[Bug]: EventIterator is not able to read the value of the field properly #90

@diegolovison

Description

@diegolovison

JAFAR Version

0.11.0

JDK Version

Eclipse Adoptium - 21.0.8

Parser Type

Other/Not Applicable

Bug Description

[Bug]: EventIterator is not able to read the value of the field properly

Steps to Reproduce

Here is the Java code

package com.example;

import io.jafar.parser.api.EventIterator;
import io.jafar.parser.api.HandlerRegistration;
import io.jafar.parser.api.JafarParser;
import io.jafar.parser.api.JafarRecordedEvent;
import io.jafar.parser.api.JfrField;
import io.jafar.parser.api.JfrType;
import io.jafar.parser.api.TypedJafarParser;

import java.nio.file.Paths;
import java.util.Map;

public class ScheduledFireTimeEventParser {

    @JfrType("io.hyperfoil.ScheduledFireTimeEvent")
    public interface ScheduledFireTimeEvent {

        @JfrField("phaseDef")
        String phaseDef();
    }

    public static void main(String[] args) throws Exception {

        String jfrFile = "/home/dlovison/Downloads/test.jfr";

        try (TypedJafarParser p = JafarParser.newTypedParser(Paths.get(jfrFile))) {
            HandlerRegistration<ScheduledFireTimeEvent> reg = p.handle(ScheduledFireTimeEvent.class, (e, ctl) -> {
                if (e.phaseDef() == null) {
                    System.err.println("phaseDef is null");
                }
            });
            p.run();
            reg.destroy(p);
        }

        try (EventIterator it = EventIterator.open(Paths.get(jfrFile))) {
            while (it.hasNext()) {
                JafarRecordedEvent event = it.next();
                if ("io.hyperfoil.ScheduledFireTimeEvent".equals(event.typeName())) {
                    Map<String, Object> data = event.value();
                    Object phaseDef = data.get("phaseDef");
                    if (phaseDef == null) {
                        System.err.println("phaseDef is null");
                    }
                }
            }
        }
    }
}

if (e.phaseDef() == null) { is never null
BUT
if (phaseDef == null) { is returning null

The value of phaseDef is a .toString of the obejct. Value example: Phase{name='steadyState/viewUser', id=4}

Expected Behavior

Both API returning the same value

Actual Behavior

Different values based on the Iterator

Stack Trace


Code Sample

Sample JFR File

No response

Additional Context

No response

Checklist

  • I have searched existing issues to ensure this is not a duplicate
  • I have tested with the latest version of JAFAR
  • I can provide a minimal JFR file to reproduce this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions