Skip to content

Fix Reflections stack traces when process yml files in classpath and …#12991

Merged
andsel merged 2 commits intoelastic:masterfrom
andsel:fix/reflection_stack_trace_for_not_recognized_resources
Jun 16, 2021
Merged

Fix Reflections stack traces when process yml files in classpath and …#12991
andsel merged 2 commits intoelastic:masterfrom
andsel:fix/reflection_stack_trace_for_not_recognized_resources

Conversation

@andsel
Copy link
Contributor

@andsel andsel commented Jun 16, 2021

Release notes

[rn:skip]

What does this PR do?

Adds a filter to Reflections library when it scan org.logstash.plugins to include only .class files and avoid to load and process AliasRegistry.yml and plugin_aliases.yml. Fixes #12992

Why is it important/What is the impact to the user?

Avoid to see stacktrace error when Logstash is run in debug

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files (and/or docker env variables)
  • I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • try a local run and see that not stacktraces heppears

How to test this PR locally

Run Logstash with bin/logstash -e "input {stdin{}} output{stdout{ codec => rubydebug}}" --log.level debug and check no stacktraces are present in console.

Related issues

Use cases

Screenshots

Logs

[2021-06-16T09:54:30,572][DEBUG][org.reflections.Reflections] could not scan file org/logstash/plugins/plugin_aliases.yml in url jar:file:/home/andrea/workspace/logstash_andsel/logstash-core/lib/jars/logstash-core.jar!/ with scanner SubTypesScanner
org.reflections.ReflectionsException: could not create class object from file org/logstash/plugins/plugin_aliases.yml
	at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:32) ~[reflections-0.9.11.jar:?]
	at org.reflections.Reflections.scan(Reflections.java:253) [reflections-0.9.11.jar:?]
	at org.reflections.Reflections.scan(Reflections.java:202) [reflections-0.9.11.jar:?]
	at org.reflections.Reflections.<init>(Reflections.java:123) [reflections-0.9.11.jar:?]
	at org.reflections.Reflections.<init>(Reflections.java:168) [reflections-0.9.11.jar:?]
	at org.reflections.Reflections.<init>(Reflections.java:141) [reflections-0.9.11.jar:?]
	at org.logstash.plugins.discovery.PluginRegistry.discoverPlugins(PluginRegistry.java:83) [logstash-core.jar:?]
	at org.logstash.plugins.discovery.PluginRegistry.<init>(PluginRegistry.java:65) [logstash-core.jar:?]
	at org.logstash.plugins.discovery.PluginRegistry.getInstance(PluginRegistry.java:72) [logstash-core.jar:?]
	at org.logstash.plugins.factory.PluginFactoryExt.<init>(PluginFactoryExt.java:86) [logstash-core.jar:?]
	at org.logstash.execution.JavaBasePipelineExt.initialize(JavaBasePipelineExt.java:73) [logstash-core.jar:?]
	at org.logstash.execution.JavaBasePipelineExt$INVOKER$i$1$0$initialize.call(JavaBasePipelineExt$INVOKER$i$1$0$initialize.gen) [jruby-complete-9.2.19.0.jar:?]
	at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:837) [jruby-complete-9.2.19.0.jar:?]
	at org.jruby.ir.runtime.IRRuntimeHelpers.instanceSuper(IRRuntimeHelpers.java:1169) [jruby-complete-9.2.19.0.jar:?]
	at org.jruby.ir.runtime.IRRuntimeHelpers.instanceSuperSplatArgs(IRRuntimeHelpers.java:1156) [jruby-complete-9.2.19.0.jar:?]
	at org.jruby.ir.targets.InstanceSuperInvokeSite.invoke(InstanceSuperInvokeSite.java:39) [jruby-complete-9.2.19.0.jar:?]
	at home.andrea.workspace.logstash_andsel.logstash_minus_core.lib.logstash.java_pipeline.RUBY$method$initialize$0(/home/andrea/workspace/logstash_andsel/logstash-core/lib/logstash/java_pipeline.rb:47) [jruby-complete-9.2.19.0.jar:?]
Caused by: org.reflections.ReflectionsException: could not create class file from plugin_aliases.yml
	at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:102) ~[reflections-0.9.11.jar:?]
	at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:24) ~[reflections-0.9.11.jar:?]
	at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:30) ~[reflections-0.9.11.jar:?]
	... 36 more
Caused by: java.io.IOException: bad magic number: 23434845
	at javassist.bytecode.ClassFile.read(ClassFile.java:790) ~[javassist-3.26.0-GA.jar:?]
	at javassist.bytecode.ClassFile.<init>(ClassFile.java:185) ~[javassist-3.26.0-GA.jar:?]
	at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:100) ~[reflections-0.9.11.jar:?]
	at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:24) ~[reflections-0.9.11.jar:?]
	at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:30) ~[reflections-0.9.11.jar:?]
	... 36 more

@andsel andsel mentioned this pull request Jun 16, 2021
9 tasks
@andsel andsel marked this pull request as ready for review June 16, 2021 09:12
@andsel andsel requested a review from kaisecheng June 16, 2021 09:18
Copy link
Contributor

@kaisecheng kaisecheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested locally and confirmed the ReflectionsException exception has gone. A suggestion for the comment, otherwise LGTM. Thanks for the quick fix.

// the constructor of Reflection must be called only by one thread, else there is a
// risk that the first thread that completes close the Zip files for the others.
Reflections reflections = new Reflections("org.logstash.plugins");
// filter from processing all resources present in package classpath that are not classes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion
// scan all .class present in package classpath

@andsel andsel merged commit a6e9a6b into elastic:master Jun 16, 2021
andsel added a commit to andsel/logstash that referenced this pull request Jun 18, 2021
…debug is enabled (elastic#12991)

Adds a filter to Reflections library initialization so that when it scan "org.logstash.plugins" it includes only .class files and avoid to load and process AliasRegistry.yml and plugin_aliases.yml

Fixes elastic#12992

(cherry picked from commit a6e9a6b)
andsel added a commit that referenced this pull request Jun 18, 2021
…debug is enabled (#12991) (#13003)

Adds a filter to Reflections library initialization so that when it scan "org.logstash.plugins" it includes only .class files and avoid to load and process AliasRegistry.yml and plugin_aliases.yml

Fixes #12992

(cherry picked from commit a6e9a6b)
kares added a commit to kares/logstash that referenced this pull request Jul 1, 2021
* master: (41 commits)
  Test: resolve integration failure due ECS mode (elastic#13044)
  Feat: event factory support (elastic#13017)
  Doc: Add geoip database API to node stats (elastic#13019)
  Add geoip database metrics to /node/stats API (elastic#13004)
  ecs: on-by-default plus docs (elastic#12830)
  ispec: fix cross-spec leak from fatal error integration specs (elastic#13002)
  Fix UBI source URL (elastic#13008)
  update fpm to allow pkg creation on jdk11+jruby 9.2 (elastic#13005)
  Add unit test to grant that production aliases correspond to a published RubyGem (elastic#12993)
  Fix logstash.bat not setting exit code (elastic#12948)
  Use the OS separator to invoke gradlew from Rake script (elastic#13000)
  Allow per-pipeline config of ECS Compatibility mode via Central Management (elastic#12861)
  Update jinja2 dependency in docker build (elastic#12994)
  fix database manager with multiple pipelines (elastic#12862)
  Fix Reflections stack traces when process yml files in classpath and debug is enabled (elastic#12991)
  Fix/log4j routing to avoid create spurious file (elastic#12965)
  Deps: update JRuby to 9.2.19.0 (elastic#12989)
  Doc: Add tip for checking for existing field (elastic#12899)
  Added test to cover the installation of aliased plugins (elastic#12967)
  CI: Update logstash_release.json after 7.3.12 (elastic#12986)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reflections library print a stacktrace in debug log about alises yml files

3 participants