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

MustacheEnvironmentCollector with nullValue compiler option no longer works in version 2.3.1 #22039

Closed
ebussieres opened this issue Jun 20, 2020 · 1 comment
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@ebussieres
Copy link

ebussieres commented Jun 20, 2020

I've found a regression that is caused by #21060, Everything works with version 2.3.0 and it no longer works with version 2.3.1.

If you define the nullValue compiler option in mustache, it no longer works and throw an exception telling that the field is not found:

Caused by: com.samskivert.mustache.MustacheException$Context: No method or field with name 'model.id' on line 7`
        @Bean
	public Mustache.Compiler mustacheCompiler(TemplateLoader mustacheTemplateLoader,
																						Environment environment) {
		return Mustache.compiler()
						.nullValue("")
						.withLoader(mustacheTemplateLoader)
						.withCollector(collector(environment));
	}

	private Mustache.Collector collector(Environment environment) {
		MustacheEnvironmentCollector collector = new MustacheEnvironmentCollector();
		collector.setEnvironment(environment);
		return collector;
	}

I've made a simple project with a test case to demonstrate it. It can be found here. https://github.com/ebussieres/regression-21060

@ebussieres ebussieres changed the title MustacheEnvironmentCollector with nullValue compiler option no longer works MustacheEnvironmentCollector with nullValue compiler option no longer works in version 2.3.1 Jun 20, 2020
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 20, 2020
@philwebb philwebb added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 22, 2020
@philwebb philwebb added this to the 2.3.x milestone Jun 22, 2020
@ebussieres
Copy link
Author

ebussieres commented Jun 25, 2020

I think that i've found a workaround. If I use the defaultValue compiler option instead of nullValue, it seems to work.

return Mustache.compiler()
           .defaultValue("")
           .withLoader(mustacheTemplateLoader)
           .withCollector(collector(environment));

Still, I think that something has been broken since the javadoc of the nullValue method specifies this :

   /** Returns a compiler that will use the given value for any variable that resolves to
      * null, but will still raise an exception for variables for which an accessor cannot be
      * found. This is like {@link #defaultValue} except that it differentiates between missing
      * accessors, and accessors that exist but return null.
      * <ul>
      * <li>In the case of a Java object being used as a context, if no field or method can be
      * found for a variable, an exception will be raised.</li>
      * <li>In the case of a {@link Map} being used as a context, if the map does not contain
      * a mapping for a variable, an exception will be raised. If the map contains a mapping
      * which maps to {@code null}, then {@code nullValue} is used.</li>
      * </ul> */

In my case, the accessor does exist, so it shouldn't throw an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

4 participants