Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflections returns classes outside of configured package #457

Open
kevinm416 opened this issue Mar 18, 2023 · 1 comment
Open

Reflections returns classes outside of configured package #457

kevinm416 opened this issue Mar 18, 2023 · 1 comment

Comments

@kevinm416
Copy link

Both of these attempts to search for Repository sub-types within the org.tamarack.models package returned classes outside of org.tamarack.models:

new Reflections(new ConfigurationBuilder().forPackages("com.tamarack.models"))
        .getSubTypesOf(Repository.class);

new Reflections("com.tamarack.models")
        .getSubTypesOf(Repository.class);

In particular, org.springframework.data.repository.PagingAndSortingRepository and org.springframework.data.repository.CrudRepository were returned in addition to the expected results. I would expect Reflections to only return classes in the package com.tamarack.models for both of those calls. Lmk if I'm using the library wrong!

@MaikJJ
Copy link

MaikJJ commented Jul 4, 2023

I've the same issue when she package is part of another Jar file. I debugged into Reflections and noticed that in my case reason ist that the expansion of the URL of the package in the Jar discards the Package part and only keeps the jar-file part. So it scanned everything in the jar file.

I solved this by adding a filter to the configuration like that:

     Reflections reflections = new Reflections(
                new ConfigurationBuilder().forPackages(exampleClass.getPackageName())
                        .filterInputsBy(fn -> fn.contains(exampleClass.getPackageName()))
                );

Solved it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants