Skip to content

Commit 07355e6

Browse files
catch exception
1 parent 20bc5ef commit 07355e6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

spring-beans/src/main/java/org/springframework/beans/propertyeditors/ZoneIdEditor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*
2828
* @author Nicholas Williams
2929
* @author Sam Brannen
30+
* @author Ngoc Nhan
3031
* @since 4.0
3132
* @see java.time.ZoneId
3233
* @see TimeZoneEditor
@@ -38,7 +39,13 @@ public void setAsText(String text) throws IllegalArgumentException {
3839
if (StringUtils.hasText(text)) {
3940
text = text.trim();
4041
}
41-
setValue(ZoneId.of(text));
42+
try {
43+
44+
setValue(ZoneId.of(text));
45+
}
46+
catch (Exception ex) {
47+
throw new IllegalArgumentException("Failed to convert ZoneId for " + text, ex);
48+
}
4249
}
4350

4451
@Override

spring-beans/src/test/java/org/springframework/beans/propertyeditors/ZoneIdEditorTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
import org.junit.jupiter.params.provider.ValueSource;
2424

2525
import static org.assertj.core.api.Assertions.assertThat;
26+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
2627

2728
/**
2829
* @author Nicholas Williams
2930
* @author Sam Brannen
31+
* @author Ngoc Nhan
3032
*/
3133
class ZoneIdEditorTests {
3234

@@ -69,4 +71,9 @@ void getValueAsText() {
6971
assertThat(editor.getAsText()).as("The text version is not correct.").isEqualTo("America/New_York");
7072
}
7173

74+
@Test
75+
void throwIllegalArgumentException() {
76+
assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("Hello, World!"));
77+
}
78+
7279
}

0 commit comments

Comments
 (0)