spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.46k stars 38.09k forks source link

ServletRequestAttributes wrongly returns a null http session on child threads. [SPR-4433] #9111

Closed spring-projects-issues closed 16 years ago

spring-projects-issues commented 16 years ago

Sergio Bossa opened SPR-4433 and commented

The protected ServletRequestAttributes#getSession(boolean ) method returns a null session on child threads. This is wrong because it doesn't get into account what happens in the constructor:

[code] public ServletRequestAttributes(HttpServletRequest request) { Assert.notNull(request, "Request must not be null"); this.request = request; // Fetch existing session reference early, to have it available even // after request completion (for example, in a custom child thread). this.session = request.getSession(false); } [/code]

I think that the following code into the getSession method:

[code] this.session = this.request.getSession(allowCreate); return this.session; [/code]

Should be as follows:

[code] HttpSession newSession = this.request.getSession(allowCreate); if (newSession != null) { this.session = newSession; } return this.session; [/code]


Affects: 2.0.8

Issue Links:

spring-projects-issues commented 16 years ago

Sergio Bossa commented

Duplicates #9112 because of a Jira fault.