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.

Filters seem to not do anything?

See original GitHub issue

When I run the following snippet…

REFLECTIONS = new Reflections(
	            new ConfigurationBuilder()
	            .setUrls(ClasspathHelper.forJavaClassPath())
	            .setScanners(new SubTypesScanner(true))
	            .filterInputsBy(
	                    new FilterBuilder()
	                    .excludePackage("java.")
	                    .excludePackage("javax.")
	                    .add((s) -> {return s.contains(".class");}))
	            );

…I get inter alia the following errors from reflections…

org.reflections.ReflectionsException: could not create class object from file ch/qos/logback/classic/gaffer/ConfigurationDelegate.groovy
	at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:32)
	at org.reflections.Reflections.scan(Reflections.java:253)
	at org.reflections.Reflections.scan(Reflections.java:202)
	at org.reflections.Reflections.<init>(Reflections.java:123)

...

08:12:57.154 [main] DEBUG org.reflections.Reflections - expanded subtype java.io.OutputStream -> java.io.ByteArrayOutputStream

...

08:12:57.167 [main] WARN  org.reflections.Reflections - could not get type for name javax.servlet.ServletContextListener from any class loader
org.reflections.ReflectionsException: could not get type for name javax.servlet.ServletContextListener
	at org.reflections.ReflectionUtils.forName(ReflectionUtils.java:390)
	at org.reflections.Reflections.expandSuperTypes(Reflections.java:381)
	at org.reflections.Reflections.<init>(Reflections.java:126)

…even though I’ve added filters & predicates to remove files that aren’t classe, as well as the java and javax packages!

Is it me misunderstanding/doing something wrong, or is this an actual bug?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ts14iccommented, Aug 28, 2019

p.s. Initially I thought the problem was caused by FilterBuilder using a somewhat inconsistent combination of OR and AND semantics (sometimes the filter is incremental, sometimes it’s not).

A combination of include + exclude includes all classes allowed by first predicate and then excludes the remaining ones using the second predicate. An AND semantic is implied (the filter is incremental). The class is included only if it passes both filters. Looks ok.

A combination of exclude + exclude uses the AND semantic as well (the filter is incremental). A class is included only if it passes both filters

But a combination of include + include is using the OR semantic - a class is allowed if any of the predicates pass. The filter is not incremental here.

Say, I’m using includePackage("foo") and include(".*BarClass").
I’d expect only foo....BarClass to be included, but it actually includes anything that has the package foo OR has the BarClass ending.

I can create a separate issue 😃.

1reaction
ts14iccommented, Aug 24, 2019

The behavior in OP is likely caused by configurationBuilder.setExpandSuperTypes(true) set by default. The stacktraces contain expandSuperTypes.
Explicitly calling setExpandSuperTypes(false) will help.

Also, it seems that expandSuperTypes is applied AFTER filters.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Excel filter not working after certain row - YouTube
But when you run a filter you will see that it does not seem to include what you expected. So below in column...
Read more >
How To Deal With A No-Filter Problem | healthsystemcio.com
The term 'without a filter' is a pretty common one used today to describe a person who speaks without tact, seems to blurt...
Read more >
Frustrating Design Patterns: Broken Filters
Too often dealing with filters can be frustrating. Let's get them right. That means never freeze the UI on a single input, provide...
Read more >
Excel filter not working after a certain row - AuditExcel
Excel filter not working after a certain row. Understanding how this happened, why not to allow Excel to guess, and how to fix...
Read more >
How To Deal With The Person Who Has No Filter - LinkedIn
But, lacking a filter is really something different. When someone 'lacks a filter', it means that they don't give consideration to the audience, ......
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