Ok, thank you for the tips. I will modify it and get back to you :)

On Tue, Aug 17, 2021 at 9:42 AM David Morávek <d...@apache.org> wrote:

> Hi Laszlo,
>
> Please use reply-all for mailing list replies. This may help others
> finding their answer in the future ;)
>
>
>> sb.append(DeviceDetail.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
>
>
> This part will again make your key non-deterministic, because you're using
> a memory address inside the content for hashing. I don't see any other
> problem in the snippet you've sent.
>
> Best,
> D.
>
> On Tue, Aug 17, 2021 at 8:33 AM László Ciople <ciople.las...@gmail.com>
> wrote:
>
>> I modified the code to use a sha256 hash instead of the hashCode when the
>> id is not present in the object. The same behaviour was manifested still.
>> Here is the code that selects the key:
>> @Override
>>     public String getKey(AzureADIamEvent value) throws Exception {
>>         // key is the device id or the hash of the device properties
>>         String key = value.payload.properties.deviceDetail.deviceId;
>>
>>         if (key == null || key.equals("")) {
>>             LOG.warn("Device id is null or empty, using sha256 value");
>>             key = DigestUtils.sha256Hex(value.payload.properties.
>> deviceDetail.toString());
>>         }
>>
>>         return key;
>>     }
>>
>> And the definition of the class the key is created from:
>> public class DeviceDetail {
>>     @JsonProperty("browser")
>>     public String browser;
>>     @JsonProperty("deviceId")
>>     public String deviceId;
>>     @JsonProperty("displayName")
>>     public String displayName;
>>     @JsonProperty("operatingSystem")
>>     public String operatingSystem;
>>     @JsonProperty("trustType")
>>     public String trustType;
>>     @Override
>>     public String toString() {
>>         StringBuilder sb = new StringBuilder();
>>         sb.append(DeviceDetail.class.getName()).append('@').append(
>> Integer.toHexString(System.identityHashCode(this))).append('[');
>>         sb.append("browser");
>>         sb.append('=');
>>         sb.append(((this.browser == null)?"<null>":this.browser));
>>         sb.append(',');
>>         sb.append("deviceId");
>>         sb.append('=');
>>         sb.append(((this.deviceId == null)?"<null>":this.deviceId));
>>         sb.append(',');
>>         sb.append("displayName");
>>         sb.append('=');
>>         sb.append(((this.displayName == null)?"<null>":this.displayName
>> ));
>>         sb.append(',');
>>         sb.append("operatingSystem");
>>         sb.append('=');
>>         sb.append(((this.operatingSystem == null)?"<null>":this.
>> operatingSystem));
>>         sb.append(',');
>>         sb.append("trustType");
>>         sb.append('=');
>>         sb.append(((this.trustType == null)?"<null>":this.trustType));
>>         sb.append(',');
>>         if (sb.charAt((sb.length()- 1)) == ',') {
>>             sb.setCharAt((sb.length()- 1), ']');
>>         } else {
>>             sb.append(']');
>>         }
>>         return sb.toString();
>>     }
>> }
>>
>>

Reply via email to