apache / apache/grails-core

GrailsUnitTest: getIncludePlugins: Plugin with dependency with dashes

Open
#11,586 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Task List

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

### Steps to Reproduce

Include a plugin that depends on another plugin using `getIncludePlugins` in `GrailsUnitTest`.

The `def dependsOn = ...` in the plugin has to contain dashes in the plugin name, e.g.

```
// Plugin-File of the plugin
...
def dependsOn = ['some-other-plugin':'* > 1.0']
```

### Expected Behaviour

The plugin is loaded

### Actual Behaviour
```
Caused by: java.lang.NullPointerException
at org.grails.plugins.BasePluginFilter.registerDependency(BasePluginFilter.java:191)
at org.grails.plugins.IncludingPluginFilter.addPluginDependencies(IncludingPluginFilter.java:52)
at org.grails.plugins.BasePluginFilter.buildDerivedPluginList(BasePluginFilter.java:120)
at org.grails.plugins.BasePluginFilter.filterPluginList(BasePluginFilter.java:100)
at grails.plugins.DefaultGrailsPluginManager.attemptLoadPlugins(DefaultGrailsPluginManager.java:323)
at grails.plugins.DefaultGrailsPluginManager.loadPlugins(DefaultGrailsPluginManager.java:224)
at grails.boot.config.GrailsApplicationPostProcessor.initializeGrailsApplication(GrailsApplicationPostProcessor.groovy:90)
at grails.boot.config.GrailsApplicationPostProcessor.setApplicationContext(GrailsApplicationPostProcessor.groovy:225)
at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:121)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:97)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
... 33 more
```

### Environment Information

- **Grails Version:** 3.3.5
- **JDK Version:** 1.8.0_18

### Possible fix

I think the problem is that in `BasePluginFilter` the dependency is looked up using the exact name specified in `dependsOn` (`some-other-plugin`) while the plugin is registered as `someOtherPlugin` in `nameMap`:

https://github.com/grails/grails-core/blob/9cab2f3c8d0839ae1f3a056ef79fc10b664e1d1f/grails-core/src/main/groovy/org/grails/plugins/BasePluginFilter.java#L204

When starting the real application this is fixed by using `GrailsNameUtils.getPropertyNameForLowerCaseHyphenSeparatedName`, e.g. here: https://github.com/grails/grails-core/blob/9cab2f3c8d0839ae1f3a056ef79fc10b664e1d1f/grails-core/src/main/groovy/org/grails/plugins/AbstractGrailsPluginManager.java#L234

Contributor guide

Open the contributing guide

Research direction

Start in grails-core/src/main/groovy/org/grails/plugins/BasePluginFilter.java at the dependency registration code linked in the issue, then compare it with AbstractGrailsPluginManager.groovy's handling of hyphen-separated names. Reproduce the case with GrailsUnitTest and a dependency named some-other-plugin. Done means the dependent plugin loads without the NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.