Skip to content

Commit 50bd70f

Browse files
beamerblvdphilwebb
authored andcommitted
Ensure ParamTag release resources
Update ParamTag to reset values when resources are released. This prevents problems in containers that pool tags. Issue: SPR-10769
1 parent 110db37 commit 50bd70f

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ParamTag.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626
* <p>This tag must be nested under a param aware tag.
2727
*
2828
* @author Scott Andrews
29+
* @author Nicholas Williams
2930
* @since 3.0
3031
* @see Param
3132
* @see UrlTag
@@ -37,16 +38,16 @@ public class ParamTag extends BodyTagSupport {
3738

3839
private String value;
3940

40-
private Param param;
41+
private boolean valueSet;
4142

4243
// tag lifecycle
4344

4445
@Override
4546
public int doEndTag() throws JspException {
46-
param = new Param();
47-
param.setName(name);
48-
if (value != null) {
49-
param.setValue(value);
47+
Param param = new Param();
48+
param.setName(this.name);
49+
if (this.valueSet) {
50+
param.setValue(this.value);
5051
}
5152
else if (getBodyContent() != null) {
5253
// get the value from the tag body
@@ -90,6 +91,15 @@ public void setName(String name) {
9091
*/
9192
public void setValue(String value) {
9293
this.value = value;
94+
this.valueSet = true;
95+
}
96+
97+
@Override
98+
public void release() {
99+
super.release();
100+
this.name = null;
101+
this.value = null;
102+
this.valueSet = false;
93103
}
94104

95105
}

spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTagTests.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,9 +25,10 @@
2525
import org.springframework.mock.web.test.MockHttpServletResponse;
2626

2727
/**
28-
* Unit tests for ParamTag
28+
* Unit tests for {@link ParamTag}
2929
*
3030
* @author Scott Andrews
31+
* @author Nicholas Williams
3132
*/
3233
public class ParamTagTests extends AbstractTagTests {
3334

@@ -67,7 +68,7 @@ public void testParamWithBodyValue() throws JspException {
6768
assertEquals("value", parent.getParam().getValue());
6869
}
6970

70-
public void testParamWithNullValue() throws JspException {
71+
public void testParamWithImplicitNullValue() throws JspException {
7172
tag.setName("name");
7273

7374
int action = tag.doEndTag();
@@ -77,6 +78,43 @@ public void testParamWithNullValue() throws JspException {
7778
assertNull(parent.getParam().getValue());
7879
}
7980

81+
public void testParamWithExplicitNullValue() throws JspException {
82+
tag.setName("name");
83+
tag.setValue(null);
84+
85+
int action = tag.doEndTag();
86+
87+
assertEquals(Tag.EVAL_PAGE, action);
88+
assertEquals("name", parent.getParam().getName());
89+
assertNull(parent.getParam().getValue());
90+
}
91+
92+
public void testParamWithValueThenReleaseThenBodyValue() throws JspException {
93+
tag.setName("name1");
94+
tag.setValue("value1");
95+
96+
int action = tag.doEndTag();
97+
98+
assertEquals(Tag.EVAL_PAGE, action);
99+
assertEquals("name1", parent.getParam().getName());
100+
assertEquals("value1", parent.getParam().getValue());
101+
102+
tag.release();
103+
104+
parent = new MockParamSupportTag();
105+
tag.setPageContext(createPageContext());
106+
tag.setParent(parent);
107+
tag.setName("name2");
108+
tag.setBodyContent(new MockBodyContent("value2",
109+
new MockHttpServletResponse()));
110+
111+
action = tag.doEndTag();
112+
113+
assertEquals(Tag.EVAL_PAGE, action);
114+
assertEquals("name2", parent.getParam().getName());
115+
assertEquals("value2", parent.getParam().getValue());
116+
}
117+
80118
public void testParamWithNoParent() {
81119
tag.setName("name");
82120
tag.setValue("value");

0 commit comments

Comments
 (0)