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-issuemaster opened this issue Aug 7, 2018 · 3 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster 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:

  • #21371 ConcurrentModel.addAttribute(name, value) javadoc should not declare null value as acceptable
@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster 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-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Aug 8, 2018

Toshiaki Maki commented

I'm afraid that 34ddb88 not enough.

Where I got the exception was here.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.