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

BindingAwareConcurrentModel should properly react to null value [SPR-17141] #21678

Closed
spring-projects-issues opened this issue Aug 7, 2018 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Aug 7, 2018

Toshiaki Maki opened SPR-17141 and commented

BindingAwareConcurrentModel extends ConcurrentHashMap so the value in put(key, value) must not be null.
This could happen when Spring WebFlux and Rendering are used.

Here is a simple reproducible code

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.reactive.result.view.Rendering;

@SpringBootApplication
@Controller
public class DemoWebFluxExceptionApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoWebFluxExceptionApplication.class, args);
    }

    @GetMapping("/")
    public Rendering hello(Model model) throws Exception {
        String value = this.couldBeNull();
        return Rendering.view("demo").modelAttribute("value", value).build();
    }

    String couldBeNull() {
        return null;
    }
}

-Actually, ConcurrentModel which is the parent annotates value as Nullable.- (sorry, I found javadoc saids the value must not be null)

ConcurrentModel should ignore the entry if the value if null or javadoc for org.springframework.web.reactive.result.view.Rendering.Builder should clarify that the value must not be null.


Affects: 5.0.8

Reference URL: #21371

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 7, 2018

Juergen Hoeller commented

We can indeed leniently ignore a null value there, just removing an existing entry if any. This makes us more aligned with the Model contract as well. Thanks for the suggestion!

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 8, 2018

Toshiaki Maki commented

I'm afraid that 34ddb888510105e2e32e18f1116487c440c42988 is not enough.

Where I got the exception was here.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 8, 2018

Juergen Hoeller commented

I've factored the null check out into put itself, also overriding putAll to delegate to put.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants