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

7.0.7 - DatastoreServiceMethodInvokingFactoryBean - FactoryBean threw exception from getObjectType #1368

Closed
4 tasks done
zyro23 opened this issue Aug 17, 2020 · 0 comments
Closed
4 tasks done
Assignees
Milestone

Comments

@zyro23
Copy link
Contributor

zyro23 commented Aug 17, 2020

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. run referenced sample app
  2. see errors/stacktrace

Expected Behaviour

injection should work, sample app should start

Actual Behaviour

depending on how/where a data service is autowired, spring may inspect the data service bean before it is initialized (e.g. @Autowired into a BeanPostProcessor, see sample app).

in this case, DatastoreServiceMethodInvokingFactoryBean.getObjectType() throws an exception which violates the FactoryBean.getObjectType contract:

2020-08-17 09:10:42.258  INFO --- [  restartedMain] o.s.b.f.s.DefaultListableBeanFactory     : FactoryBean threw exception from getObjectType, despite the contract saying that it should return null if the type of its object cannot be determined yet

java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at org.codehaus.groovy.runtime.BytecodeInterface8.objectArrayGet(BytecodeInterface8.java:362)
	at org.grails.datastore.mapping.config.DatastoreServiceMethodInvokingFactoryBean.getObjectType(DatastoreServiceMethodInvokingFactoryBean.groovy:25)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getTypeForFactoryBean(FactoryBeanRegistrySupport.java:64)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:869)
	at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:574)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:523)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:486)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:471)
	at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:163)
	at org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer.getUserConfigurationResults(NoSuchBeanDefinitionFailureAnalyzer.java:135)
	at org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer.analyze(NoSuchBeanDefinitionFailureAnalyzer.java:84)
	at org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer.analyze(NoSuchBeanDefinitionFailureAnalyzer.java:60)
	at org.springframework.boot.diagnostics.analyzer.AbstractInjectionFailureAnalyzer.analyze(AbstractInjectionFailureAnalyzer.java:40)
	at org.springframework.boot.diagnostics.AbstractFailureAnalyzer.analyze(AbstractFailureAnalyzer.java:35)
	at org.springframework.boot.diagnostics.FailureAnalyzers.analyze(FailureAnalyzers.java:110)
	at org.springframework.boot.diagnostics.FailureAnalyzers.reportException(FailureAnalyzers.java:103)
	at org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:813)
	at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:798)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
	at grails.boot.GrailsApp.run(GrailsApp.groovy:99)
	at grails.boot.GrailsApp.run(GrailsApp.groovy:485)
	at grails.boot.GrailsApp.run(GrailsApp.groovy:472)
	at myapp.Application.main(Application.groovy:13)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

2020-08-17 09:10:42.280 ERROR --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field dummyDataService in myapp.MyBeanPostProcessor required a bean of type 'myapp.DummyDataService' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'myapp.DummyDataService' in your configuration.

Environment Information

  • Operating System: win x64
  • GORM Version: 7.0.7
  • Grails Version (if using Grails): 4.0.4
  • JDK Version: openjdk 11.0.7+10

Example Application

sample app will be referenced asap

zyro23 added a commit to zyro23/grails-data-mapping-1368 that referenced this issue Aug 17, 2020
@puneetbehl puneetbehl self-assigned this Aug 17, 2020
zyro23 added a commit to zyro23/grails-data-mapping that referenced this issue Aug 18, 2020
… classloader where appropriate

- DatastoreServiceMethodInvokingFactoryBean.getObjectType returns null if not initialized (i.e. arguments is null, getArguments() returns Object[]). that allows AbstractAutowireCapableBeanFactory to initialize DatastoreServiceMethodInvokingFactoryBean if necessary

- AbstractDatastoreInitializer and SoftServiceLoader use the context classloader to load data service classes. this way, autowiring data services by type works reliably with spring boot devtools restart (RestartClassLoader)
zyro23 added a commit to zyro23/grails-data-mapping that referenced this issue Aug 18, 2020
puneetbehl added a commit that referenced this issue Aug 18, 2020
#1368 - respect FactoryBean.getObjectType contract, use context…
@puneetbehl puneetbehl added this to the 7.0.8 milestone Aug 18, 2020
zyro23 added a commit to zyro23/gorm-hibernate5 that referenced this issue Aug 18, 2020
…ped data services works targeting Configuration beans as well as BeanPostProcessor beans
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