Duplicated Lines of Code

We are using SonarQube 8.9 LTS version.

Can you please explain why SonarQube is complaining these lines of code is duplicate lines? The only similarity I can see in these lines is the “router.options”/“router.get” and path ‘/nee/workeridentity/v1/workers/:slid’

I have to give a brief explanation to the developers. Developers are saying SonarQube is incorrectly reporting duplicate lines.

Here are screenshots:

Thank you.


Strings values are ignored in duplication detection. So this “collapses to”

router.get('...', (req: Request, res: Response) => {

router.get('...', authenticationHook,

over and over again.


Thank you Ann,

So the “router.get” and “router.options” are causing the duplication?
What do you suggest to resolve this duplication?


Yes. TBH, I’m not a fan of the way we detect that a chunk of code “duplicates” an overlap of itself, but that’s what the popup in your first screenshot is showing you: that lines 78-93(???) are duplicated by lines 84-99.


Hi Ann,

The developer changed the literals and the dups are resolved.
Do you have any documentation where I can see the what code or rules for duplication?


Well, yes. The literals are gone now. But the code is different too. :woman_shrugging:

We do, but it’s not fulsome. In fact, I looked this up yesterday before I answered you but didn’t link to it because a) it’s a bit thin and b) I believe the last sentence in ‘Language-specific details’ (“Differences in indentation and in string literals are ignored while detecting duplications.”) applies to all languages, not just Java. (Yes, I’ve raised that internally.)