Duplicate Inspection for Apex not working as expected

Issue #2362 resolved
Jason van Beukering created an issue

Hi Scott,

  • Not sure if this is an IC issue or a Webstorm issue, but until recently duplicate managed no longer works in general. I have attached screenshots of my duplicate detection setup as well as a snippet that should be detected as a duplicate.

Could you take a look and see if there is indeed an issue… I can send my inspection profile if that would assist?

Comments (9)

  1. Scott Wells repo owner

    Jason, it looks like there are (at least) three different concepts included in this question.

    Your first screenshot for Editor > Duplicates is not something I’ve explicitly implemented for IC2 so I’m a bit surprised to see Apex listed there. I’ll need to investigate what that’s doing and its relationship with the other two to see if there’s anything I need to do to make it work (or improve how it’s working.

    The Salesforce Duplicate declaration code inspection from the third screenshot is to warn about identifier names that are used more than once in the same declaration scope, e.g.:

    The Duplicate code fragment inspection is what detects repetition of the same code above the configured threshold, e.g.:

    I think that’s what you’re asking about here, correct? That should just work, and the configured threshold in your second screenshot looks low enough to catch the duplicate code shown in your last one. Do you see the same behavior if you copy/paste that block of code twice into an anonymous Apex tab, or are the duplicates properly reported? Also, can you confirm that the Duplicate code fragment inspection is enabled in your project’s active inspection profile?

  2. Jason van Beukering reporter

    Yes, least point is correct. Just wanted to share all my settings with you. The inspection is enabled. Others in my team have no issue however and it feels like something has been cached or persisted that's causing this behaviour. Tried a duplicate snippet as per below in anonymous Apex Tab and got now inspection warnings.

  3. Scott Wells repo owner

    Okay. There’s not really any caching in play here, at least not anything explicit in IC2. It just provides information to the JetBrains duplicate code fragment inspection about which types of tokens should be considered, which should be anonymized, etc., and how to weight each when building a “score”.

    Let’s see if that inspection is working at all. Can you create a scratch file in another language, e.g., JavaScript, and add a few repeated code blocks of sufficient size to trigger the inspection for that language? If that works and Apex doesn’t, we’ll check your idea.log. If that doesn’t work, there’s something going on with that inspection altogether.

  4. Jason van Beukering reporter

    So, tried in javascript (specifically in an Lwc components) and duplicates detected no problem; actually running across our base multiple (valid) duplicates detected. Just not for Apex… and yesterday afternoon this was working…

  5. Scott Wells repo owner

    Yeah, that’s weird. There’s just not much going on there, to be honest. IC2 just answers some basic questions about the tokens in a token stream and whether they should be included in duplicate block evaluation. Do you see any errors in idea.log, specifically anything from com.illuminatedcloud.intellij.inspection.duplicateScope.ApexDuplicateScope?

    Also, do you see this behavior in other IC2 projects? What happens if you create a brand new IC2 project and force some duplicates?

    Note that I’m stepping away for a bit this afternoon so further responses will lag, but I’ll take a look at whatever you send in response to this when I’m back.

  6. Jason van Beukering reporter

    Okay, the two projects I was working on yesterday no longer detect duplicates, however, a project I hadn’t touched in a while does… I created a new project and that too works. I don’t think worth pursuing this right now, will resurrect this issue if it reoccurs. Thanks for your help

  7. Scott Wells repo owner

    Okay. I'll go ahead and resolve this, though trust that I don't consider it truly "resolved". If/when you see this behavior again, either reopen this one or log a new one and we'll investigate further.

  8. Log in to comment