Codebase list joda-convert / 994c665
Updated version 1.8.3 from 'upstream/1.8.3' with Debian dir 352d1389b3b3897981a3fbce75e026a316124ce0 Emmanuel Bourg 6 years ago
10 changed file(s) with 133 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
5151
5252
5353 ### Releases
54 [Release 1.8.2](http://www.joda.org/joda-convert/download.html) is the current latest release.
54 [Release 1.8.3](http://www.joda.org/joda-convert/download.html) is the current latest release.
5555 This release is considered stable and worthy of the 1.x tag.
5656 It depends on Java SE 6 or later.
5757
58 Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.joda|joda-convert|1.8.2|jar)
58 Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.joda|joda-convert|1.8.3|jar)
5959
6060
6161 ### Support
88 <artifactId>joda-convert</artifactId>
99 <packaging>jar</packaging>
1010 <name>Joda-Convert</name>
11 <version>1.8.2</version>
11 <version>1.8.3</version>
1212 <description>Library to convert Objects to and from String</description>
1313 <url>http://www.joda.org/joda-convert/</url>
1414
386386 <dependency>
387387 <groupId>com.google.guava</groupId>
388388 <artifactId>guava</artifactId>
389 <version>18.0</version>
389 <version>20.0</version>
390390 <optional>true</optional>
391391 </dependency>
392392 <dependency>
66
77 <body>
88 <!-- types are add, fix, remove, update -->
9 <release version="1.8.3" date="2017-08-21" description="Version 1.8.3">
10 <action dev="jodastephen" type="update" >
11 Optional Guava dependency updated to v20.0.
12 As Guava is accessed only by reflection guarded by try-catch, any version of Guava may be used by end users.
13 This version has been selected for the pom.xml as it is the last version for Java 1.6.
14 </action>
15 <action dev="jodastephen" type="update" >
16 Provide ability to lock rename handler for additional security.
17 Prevent renames of java.*, javax.* and org.joda.* types.
18 </action>
19 </release>
920 <release version="1.8.2" date="2017-06-28" description="Version 1.8.2">
1021 <action dev="jodastephen" type="fix" >
1122 Fix to ensure primitive types can be deserialized.
381381 if (str.length() != 29) {
382382 throw new IllegalArgumentException("Unable to parse date: " + str);
383383 }
384 str = str.substring(0, 26) + str.substring(27);
384 String str2 = str.substring(0, 26) + str.substring(27);
385385 SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
386386 try {
387 return f.parseObject(str);
387 return f.parseObject(str2);
388388 } catch (ParseException ex) {
389389 throw new RuntimeException(ex);
390390 }
412412 throw new IllegalArgumentException("Unable to parse date: " + str);
413413 }
414414 TimeZone zone = TimeZone.getTimeZone(str.substring(30, str.length() - 1));
415 str = str.substring(0, 26) + str.substring(27, 29);
415 String str2 = str.substring(0, 26) + str.substring(27, 29);
416416 SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
417417 GregorianCalendar cal = new GregorianCalendar(zone);
418418 cal.setTimeInMillis(0);
419419 f.setCalendar(cal);
420420 try {
421 f.parseObject(str);
421 f.parseObject(str2);
422422 return f.getCalendar();
423423 } catch (ParseException ex) {
424424 throw new RuntimeException(ex);
3232 * </pre>
3333 * The recommended usage is to edit the static singleton before using other classes.
3434 * Editing a static is acceptable because renames are driven by bytecode which is static.
35 * For additional security, an application should lock the rename handler instance
36 * once any types and enums have been registered using {@link #lock()}.
3537 * <p>
3638 * This class is thread-safe with concurrent caches.
3739 *
4648 public static final RenameHandler INSTANCE = new RenameHandler();
4749
4850 /**
51 * The lock flag.
52 */
53 private volatile boolean locked;
54 /**
4955 * The type renames.
5056 */
5157 private final ConcurrentHashMap<String, Class<?>> typeRenames =
7884 //-----------------------------------------------------------------------
7985 /**
8086 * Register the fact that a type was renamed.
87 * <p>
88 * This handles the use case where a class is renamed.
8189 *
8290 * @param oldName the old name of the type including the package name, not null
8391 * @param currentValue the current type, not null
8997 if (currentValue == null) {
9098 throw new IllegalArgumentException("currentValue must not be null");
9199 }
100 if (oldName.startsWith("java.") || oldName.startsWith("javax.") || oldName.startsWith("org.joda.")) {
101 throw new IllegalArgumentException("oldName must not be a java.*, javax.* or org.joda.* type");
102 }
103 checkNotLocked();
92104 typeRenames.put(oldName, currentValue);
93105 }
94106
164176 //-----------------------------------------------------------------------
165177 /**
166178 * Register the fact that an enum constant was renamed.
179 * <p>
180 * This handles the use case where an enum constant is renamed, but the enum class remains the same.
167181 *
168182 * @param oldName the old name of the enum constant, not null
169183 * @param currentValue the current enum constant, not null
175189 if (currentValue == null) {
176190 throw new IllegalArgumentException("currentValue must not be null");
177191 }
192 checkNotLocked();
178193 Class<?> enumType = currentValue.getDeclaringClass();
179194 Map<String, Enum<?>> perClass = enumRenames.get(enumType);
180195 if (perClass == null) {
239254 }
240255
241256 //-----------------------------------------------------------------------
257 /**
258 * Locks this instance of the rename handler.
259 * <p>
260 * For additional security, an application should lock the rename handler
261 * once any types and enums have been registered.
262 */
263 public void lock() {
264 checkNotLocked();
265 locked = true;
266 }
267
268 // ensure not locked
269 private void checkNotLocked() {
270 if (locked) {
271 throw new IllegalStateException("RenameHandler has been locked and it cannot now be changed");
272 }
273 }
274
275 //-----------------------------------------------------------------------
242276 @Override
243277 public String toString() {
244278 return "RenamedTypes" + typeRenames + ",RenamedEnumConstants" + enumRenames;
3131 extends AbstractTypeStringConverter
3232 implements TypedStringConverter<Type> {
3333
34 public TypeStringConverter() {
34 TypeStringConverter() {
3535 }
3636
3737 @Override
2929 extends AbstractTypeStringConverter
3030 implements TypedStringConverter<TypeToken<?>> {
3131
32 public TypeTokenStringConverter() {
32 TypeTokenStringConverter() {
3333 }
3434
3535 @Override
101101 if (str.length() == 0) {
102102 return EMPTY;
103103 }
104 Character[] array = new Character[str.length()];
104 String adjusted = str;
105 Character[] array = new Character[adjusted.length()];
105106 int arrayPos = 0;
106107 int pos;
107 while ((pos = str.indexOf('\\')) >= 0) {
108 while ((pos = adjusted.indexOf('\\')) >= 0) {
108109 for (int i = 0; i < pos; i++) {
109 array[arrayPos++] = str.charAt(i);
110 array[arrayPos++] = adjusted.charAt(i);
110111 }
111 if (str.charAt(pos + 1) == '\\') {
112 if (adjusted.charAt(pos + 1) == '\\') {
112113 array[arrayPos++] = '\\';
113 } else if (str.charAt(pos + 1) == '-') {
114 } else if (adjusted.charAt(pos + 1) == '-') {
114115 array[arrayPos++] = null;
115116 } else {
116117 throw new IllegalArgumentException("Invalid Character[] string, incorrect escape");
117118 }
118 str = str.substring(pos + 2);
119 adjusted = adjusted.substring(pos + 2);
119120 }
120 for (int i = 0; i < str.length(); i++) {
121 array[arrayPos++] = str.charAt(i);
121 for (int i = 0; i < adjusted.length(); i++) {
122 array[arrayPos++] = adjusted.charAt(i);
122123 }
123124 return Arrays.copyOf(array, arrayPos);
124125 }
7575
7676 ## <i></i> Releases
7777
78 [Release 1.8.2](download.html) is the current latest release.
78 [Release 1.8.3](download.html) is the current latest release.
7979 This release is considered stable and worthy of the 1.x tag.
8080
8181 Joda-Convert requires Java SE 6 or later and has [no dependencies](dependencies.html).
8282
83 Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.joda%7Cjoda-convert%7C1.8.2%7Cjar).
83 Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.joda%7Cjoda-convert%7C1.8.3%7Cjar).
8484
8585 ```xml
8686 <dependency>
8787 <groupId>org.joda</groupId>
8888 <artifactId>joda-convert</artifactId>
89 <version>1.8.2</version>
89 <version>1.8.3</version>
9090 </dependency>
9191 ```
9292
0 /*
1 * Copyright 2010-present Stephen Colebourne
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.joda.convert;
16
17 import org.junit.Assert;
18 import org.junit.Test;
19
20 /**
21 * Test {@link RenameHandler}.
22 */
23 public class TestRenameHandler {
24
25 @Test
26 public void test_matchRenamedType() throws ClassNotFoundException {
27 RenameHandler test = RenameHandler.create();
28 test.renamedType("com.foo.Bar", TestRenameHandler.class);
29 Class<?> renamed = test.lookupType("com.foo.Bar");
30 Assert.assertEquals(TestRenameHandler.class, renamed);
31 }
32
33 @Test(expected = ClassNotFoundException.class)
34 public void test_noMatchType() throws ClassNotFoundException {
35 RenameHandler test = RenameHandler.create();
36 test.lookupType("com.foo.Foo");
37 }
38
39 @Test(expected = IllegalArgumentException.class)
40 public void test_renameBlockedType1() {
41 RenameHandler test = RenameHandler.create();
42 test.renamedType("java.lang.String", TestRenameHandler.class);
43 }
44
45 @Test(expected = IllegalArgumentException.class)
46 public void test_renameBlockedType2() {
47 RenameHandler test = RenameHandler.create();
48 test.renamedType("javax.foo.Bar", TestRenameHandler.class);
49 }
50
51 @Test(expected = IllegalArgumentException.class)
52 public void test_renameBlockedType3() {
53 RenameHandler test = RenameHandler.create();
54 test.renamedType("org.joda.foo.Bar", TestRenameHandler.class);
55 }
56
57 @Test(expected = IllegalStateException.class)
58 public void test_locked() {
59 RenameHandler test = RenameHandler.create();
60 test.renamedType("com.foo.Bar", TestRenameHandler.class);
61 test.lock();
62 test.renamedType("com.foo.Foo", TestRenameHandler.class);
63 }
64
65 }