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

0.10-RC1: Incorrect example for TypesAnnotated.with() #337

Closed
davidburstrom opened this issue Sep 25, 2021 · 13 comments
Closed

0.10-RC1: Incorrect example for TypesAnnotated.with() #337

davidburstrom opened this issue Sep 25, 2021 · 13 comments

Comments

@davidburstrom
Copy link

davidburstrom commented Sep 25, 2021

In the example in the readme it states that

Set<Class<?>> annotated = 
  reflections.get(TypesAnnotated.with(SomeAnnotation.class));

In 0.10-RC1, it results in a Set<String>, as with() is backed by default QueryFunction<Store, String> with(Class<?>... keys) { return of(keys); }. Not only that, the collection is empty contrary to what was returned in 0.9.12.

@ronmamo
Copy link
Owner

ronmamo commented Sep 25, 2021

thanks @davidburstrom , I've fixed the readme example.
as for the empty result - shouldn't happen unless the scanner was configured, as tested in ReflectionsQueryTest. can you check the configuration or share how Reflections was instantiated?
(ref pr)

@davidburstrom
Copy link
Author

I'm a little surprised though, I'd have thought the README actually was more correct than the code.

What I used in 0.9.12 was

  public static Set<Class<?>> getValidStuff() {
    return new Reflections("valid").getTypesAnnotatedWith(Stuff.class);
  }

which worked great.

In 0.10-RC1, I had to adapt the return type to

  public static Collection<Class<?>> getValidStuff() {
    return new Reflections("valid").getTypesAnnotatedWith(Stuff.class);
  }

which stopped returning results.

Further changing of that into

  public static Set<String> getValidStuff() {
    return new Reflections("valid").get(TypesAnnotated.with(Stuff.class));
  }

brought me even further from the target, and didn't return anything either.

@ronmamo
Copy link
Owner

ronmamo commented Sep 26, 2021

will change the results from Collection back to Set.

empty result - suspected changes are in ConfigurationBuilder or FilterBuilder, can you check the differences in the effective reflections.getConfiguration()?

preferably use the explicit constructor to avoid ambiguity (will improve javadoc/readme), such as

new Reflections(new ConfigurationBuilder().addUrls(ClasspathHelper.forPackage("valid")))
// or
new Reflections(new ConfigurationBuilder()
  .addUrls(ClasspathHelper.forPackage("valid")) 
  .setInputFilter(new FilterBuilder().includePattern(".*"))) // <-- optionally

either of the above will provide workable input, thanks for the coop!

@davidburstrom
Copy link
Author

I personally have nothing against using Collection over Set in this case, but I suppose it does clarify that there will be no duplicates.

With 0.9.12 and

new Reflections("valid").getTypesAnnotatedWith(OptionsInterface.class);

the configuration looks like

0 9 12-configuration

and with 0.10-RC1 and

    final ConfigurationBuilder configurationBuilder =
    new ConfigurationBuilder().addUrls(ClasspathHelper.forPackage("valid"));
    configurationBuilder.setInputsFilter(new FilterBuilder().includePattern(".*"));
    final Reflections reflections = new Reflections(configurationBuilder);

the configuration looks like

0 10-rc1-configuration

The URLs are identical and I've confirmed that they contain the expected classes.

I've yet to find a spec that produces any output.

@ronmamo
Copy link
Owner

ronmamo commented Sep 26, 2021

thanks @davidburstrom for your valuable feedback and time! these will be addressed for the next release.

@davidburstrom
Copy link
Author

Trying out RC2, there are no changes required to use the Reflections API, but still, when querying for all types annotated with X, there are zero results where there used to be non-zero with 0.9.12.

@ronmamo
Copy link
Owner

ronmamo commented Oct 4, 2021

thanks @davidburstrom , but I couldn't find a way to reproduce it. it might be some javassist issue (downgrade can provide more input). you can send me the jar on email and i'll take a closer look.

@davidburstrom
Copy link
Author

I'll try and reproduce it in a self-enclosed project, hang on.

@davidburstrom
Copy link
Author

repro-337.zip

There you go, fails on my machine at least. Just run gradle build. I didn't provide a Gradle wrapper script.

@ronmamo
Copy link
Owner

ronmamo commented Oct 5, 2021

ok got it. this is now marked as a known issue and will be fixed on next release, looks like it's going to be earlier than I thought...
as a workaround for 0.10, mark your annotation with @Retention(RUNTIME)

@davidburstrom
Copy link
Author

Great, thanks!

@ronmamo
Copy link
Owner

ronmamo commented Oct 8, 2021

fixed in 0.10.1

@ronmamo ronmamo closed this as completed Oct 8, 2021
@davidburstrom
Copy link
Author

I can confirm the fix works as intended in 0.10.1 :)

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

No branches or pull requests

2 participants