question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFE: Duplicate checker

See original GitHub issue

I have used this library to implement a classpath duplicate checker. The gist of it is basically:

Map<String, List<String>> check() {
        Map<String, List<String>> seen = new HashMap<>();
        try (ScanResult scanResult = new ClassGraph().enableClassInfo().ignoreClassVisibility().scan()) {
            for (Resource resource : scanResult.getAllResources()) {
                String path = resource.getPath();
                @Var List<String> classpathElements = seen.get(path);
                if (classpathElements == null) {
                    classpathElements = new ArrayList<>(1);
                    seen.put(path, classpathElements);
                }
                classpathElements.add(getClasspathElementString(resource));
            }
        }
        return seen.entrySet().stream().filter(entry -> entry.getValue().size() > 1)
                .filter(entry -> !isHarmlessDuplicate(entry.getKey()))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    }

Basically I re-built something very similar to https://github.com/jhades/ (see http://jhades.github.io) or https://github.com/basepom/duplicate-finder-maven-plugin but using classgraph. (The motivation for this was that JHades could not support Java 9+.)

Filing this issue here to ask whether a contribution (PR) of utility class like my ClasspathHellDuplicatesChecker into this lib would be of any interest. Alternative I could just add a link to it somewhere in the doc to make it easier and let people build something like it.

Also absolutely no offense taken if this doesn’t fit here - just close in that case, no worries.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lukehutchcommented, Feb 5, 2019

Erm … but that’s perfectly fine, right? That’s kind of the point of what I’m after - to find duplicate classes in different JARs, when you (or an external 3rd-party) made a mess of your dependencies. You can’t really have a duplicate of the exact same class in the same single JAR.

Yes, it’s fine, I just wanted to make the distinction between multiple listings of the same jar on the classpath, and multiple occurrences of the same file within different classpath elements. The first cannot be detected (but may still be considered by somebody to be problematic), but the second can.

0reactions
vorburgercommented, Feb 5, 2019

if the exact same path or URL (after canonicalization) is listed on the classpath or module path multiple times, the second and subsequent are ignored by ClassGraph (since that is more of less semantically what the JRE does too). Therefore, duplicates are only detected if the same resources are present in multiple different modules, jars or directories.

Erm … but that’s perfectly fine, right? That’s kind of the point of what I’m after - to find duplicate classes in different JARs, when you (or an external 3rd-party) made a mess of your dependencies. You can’t really have a duplicate of the exact same class in the same single JAR.

Maintaining isHarmlessDuplicate() over the years is going to be a Herculean effort, good luck 😄

I’m not planning to… 😈

PS you should assign the ScanResult in a try-with-resources statement, so that proper cleanup does not depend upon a finalizer.

Thanks for noticing and pointing it out - fixed in https://git.opendaylight.org/gerrit/#/c/80158.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RFE: Find Duplicates - Highlight Alternating Dups - voidtools
RFE : Find Duplicates - Highlight Alternating Dups ... it's a duplicate file finder, so (generally) can't deal with random file locations, ...
Read more >
RFE: Change DNS duplicate checking to be an option
Hi, As asked in this support ticket: Ignore duplicate DNS in case of external nameservers I am asking for an enhancement on foreman....
Read more >
Do Any one has experience sending DUPLICATE RFE?
to redwings: Yes, you use a copy of the old RFE and add what you need to giving the reasons why it was...
Read more >
How to Reply To Duplicate RFE : r/USCIS - Reddit
Most civil surgeons will give you a 2nd copy for free or $5-$10. Just call them and ask. You can fight it with...
Read more >
RFE: "include duplicate copies when consular notification is ... - Avvo
With RFE stating: "include duplicate copies when consular notification is requested" means submit a duplicate for the US Consulate ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found