unloggedio / unlogged-sdk

Unlogged SDK for recording JAVA code execution
https://unlogged.io
Apache License 2.0
174 stars 16 forks source link

2 candidates generated for a method where 1 was expected #80

Closed TheAmg closed 1 month ago

TheAmg commented 3 months ago

Describe the bug

2 candidates are generated in the place of 1 if the following curl is invoked with unlogged-spring-maven-demo. curl - 1 ("findById")

curl --location 'http://localhost:8080/property/find?id=1' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhbWdAYW1nLmNvbSIsImV4cCI6MTkyNTYzOTMwN30.OBu-67QShlyZdY3sm4BxKbdye4nAsxeHvr5o85aG2YM'

On hitting this, and candidates load there will be 2 candidates for the method getById from PropertyServiceCEImpl. 1 with the correct return type PropertyDetails and the other with returnType Object.

This behaviour is not seen if the curl for findAll is used (there will only be 1 controller related candidate and 1 service related candidate).

curl - 2 ("findAll")

curl --location 'http://localhost:8080/property/findAll' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhbWdAYW1nLmNvbSIsImV4cCI6MTkyNTYzOTMwN30.OBu-67QShlyZdY3sm4BxKbdye4nAsxeHvr5o85aG2YM'

This might be happening due to CrudService (interface) methods that PropertyServiceCEImpl implements. The only distinguishing factor I see is that findAll() has no args and getById has an arg (parametrized).

Reproduction steps

  1. Start unlogged-spring-maven-demo with 0.6.2.
  2. Hit curl-1 from postman and check the list of candidates generated.

https://github.com/unloggedio/unlogged-sdk/assets/68552461/bfb16073-38e8-4a6f-bf28-d39024aa195c

Expected behavior

For only the candidate with the correct return type to be shown.

Additional context

No response

kartikeytewari-ul commented 2 months ago

RCA

Decompiled Method

 public java.lang.Object getById(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Ljava/lang/Object;
    flags: (0x1041) ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_0
         1: aload_1
         2: checkcast     #11                 // class java/lang/Long
         5: invokevirtual #187                // Method getById:(Ljava/lang/Long;)Lorg/unlogged/demo/models/abstraction/PropertyDetails;
         8: areturn
      LineNumberTable:
        line 9: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       9     0  this   Lorg/unlogged/demo/service/abstractions/PropertyServiceCEImpl;
    MethodParameters:
      Name                           Flags
      id                             synthetic

Proposed Fix

kartikeytewari-ul commented 2 months ago

Example of Synthetic injection is here.

kartikeytewari-ul commented 1 month ago

This is fixed with PR #112