RFE: Duplicate checker
See original GitHub issueI 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:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.
I’m not planning to… 😈
Thanks for noticing and pointing it out - fixed in https://git.opendaylight.org/gerrit/#/c/80158.