File tree 2 files changed +19
-5
lines changed
main/java/org/springframework/beans/propertyeditors
test/java/org/springframework/beans/propertyeditors
2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package org .springframework .beans .propertyeditors ;
18
18
19
19
import java .beans .PropertyEditorSupport ;
20
+ import java .time .DateTimeException ;
20
21
import java .time .ZoneId ;
21
22
22
23
import org .springframework .util .StringUtils ;
23
24
24
25
/**
25
- * Editor for {@code java.time.ZoneId}, translating zone ID Strings into {@code ZoneId}
26
- * objects. Exposes the {@code TimeZone} ID as a text representation.
26
+ * Editor for {@code java.time.ZoneId}, translating time zone Strings into {@code ZoneId}
27
+ * objects. Exposes the time zone as a text representation.
27
28
*
28
29
* @author Nicholas Williams
29
30
* @author Sam Brannen
31
+ * @author Juergen Hoeller
30
32
* @since 4.0
31
33
* @see java.time.ZoneId
32
34
* @see TimeZoneEditor
@@ -38,7 +40,12 @@ public void setAsText(String text) throws IllegalArgumentException {
38
40
if (StringUtils .hasText (text )) {
39
41
text = text .trim ();
40
42
}
41
- setValue (ZoneId .of (text ));
43
+ try {
44
+ setValue (ZoneId .of (text ));
45
+ }
46
+ catch (DateTimeException ex ) {
47
+ throw new IllegalArgumentException (ex .getMessage (), ex );
48
+ }
42
49
}
43
50
44
51
@ Override
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
import org .junit .jupiter .params .provider .ValueSource ;
24
24
25
25
import static org .assertj .core .api .Assertions .assertThat ;
26
+ import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
26
27
27
28
/**
28
29
* @author Nicholas Williams
29
30
* @author Sam Brannen
31
+ * @author Juergen Hoeller
30
32
*/
31
33
class ZoneIdEditorTests {
32
34
@@ -69,4 +71,9 @@ void getValueAsText() {
69
71
assertThat (editor .getAsText ()).as ("The text version is not correct." ).isEqualTo ("America/New_York" );
70
72
}
71
73
74
+ @ Test
75
+ void correctExceptionForInvalid () {
76
+ assertThatIllegalArgumentException ().isThrownBy (() -> editor .setAsText ("INVALID" )).withMessageContaining ("INVALID" );
77
+ }
78
+
72
79
}
You can’t perform that action at this time.
0 commit comments