From dff97cfdc26064e22d8f03a802ac2bc37d86da51 Mon Sep 17 00:00:00 2001 From: Afly Date: Wed, 16 Dec 2020 15:31:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?DEC-16125=20fix:=20resin=E5=92=8Cweblogic?= =?UTF-8?q?=E4=B8=8B=E5=AD=98=E5=9C=A8joda=E6=97=B6=E5=8C=BA=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=88=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third/joda/time/tz/ZoneInfoProvider.java | 36 +++++++++++++++---- .../joda/time/tz/ZoneInfoProviderTest.java | 35 ++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 fine-joda/src/test/java/com/fr/third/joda/time/tz/ZoneInfoProviderTest.java diff --git a/fine-joda/src/main/java/com/fr/third/joda/time/tz/ZoneInfoProvider.java b/fine-joda/src/main/java/com/fr/third/joda/time/tz/ZoneInfoProvider.java index 948067514..3cddda70e 100644 --- a/fine-joda/src/main/java/com/fr/third/joda/time/tz/ZoneInfoProvider.java +++ b/fine-joda/src/main/java/com/fr/third/joda/time/tz/ZoneInfoProvider.java @@ -15,6 +15,7 @@ */ package com.fr.third.joda.time.tz; +import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; @@ -24,6 +25,7 @@ import java.lang.ref.SoftReference; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Collections; +import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -52,6 +54,8 @@ public class ZoneInfoProvider implements Provider { private final Map iZoneInfoMap; /** Maps ids to strings or SoftReferences to DateTimeZones. */ private final Set iZoneInfoKeys; + /** 内置可能加载不到的带加号的资源文件. */ + private static Map GMTData = new HashMap(); /** * Search the default classloader resource path for compiled data files. @@ -217,12 +221,18 @@ public class ZoneInfoProvider implements Provider { } }); if (in == null) { - StringBuilder buf = new StringBuilder(40) - .append("Resource not found: \"") - .append(path) - .append("\" ClassLoader: ") - .append(iLoader != null ? iLoader.toString() : "system"); - throw new IOException(buf.toString()); + if (name.contains("+")) { + name = name.substring(name.indexOf("/") + 1); + byte[] data = GMTData.get(name); + return new ByteArrayInputStream(data); + } else { + StringBuilder buf = new StringBuilder(40) + .append("Resource not found: \"") + .append(path) + .append("\" ClassLoader: ") + .append(iLoader != null ? iLoader.toString() : "system"); + throw new IOException(buf.toString()); + } } } return in; @@ -302,4 +312,18 @@ public class ZoneInfoProvider implements Provider { } } + static { + GMTData.put("GMT+1", new byte[]{70, 0, 3, 45, 48, 49, 62, 62}); + GMTData.put("GMT+2", new byte[]{70, 0, 3, 45, 48, 50, 60, 60}); + GMTData.put("GMT+3", new byte[]{70, 0, 3, 45, 48, 51, 58, 58}); + GMTData.put("GMT+4", new byte[]{70, 0, 3, 45, 48, 52, 56, 56}); + GMTData.put("GMT+5", new byte[]{70, 0, 3, 45, 48, 53, 54, 54}); + GMTData.put("GMT+6", new byte[]{70, 0, 3, 45, 48, 54, 52, 52}); + GMTData.put("GMT+7", new byte[]{70, 0, 3, 45, 48, 55, 50, 50}); + GMTData.put("GMT+8", new byte[]{70, 0, 3, 45, 48, 56, 48, 48}); + GMTData.put("GMT+9", new byte[]{70, 0, 3, 45, 48, 57, 46, 46}); + GMTData.put("GMT+10", new byte[]{70, 0, 3, 45, 49, 48, 44, 44}); + GMTData.put("GMT+11", new byte[]{70, 0, 3, 45, 49, 49, 42, 42}); + } + } diff --git a/fine-joda/src/test/java/com/fr/third/joda/time/tz/ZoneInfoProviderTest.java b/fine-joda/src/test/java/com/fr/third/joda/time/tz/ZoneInfoProviderTest.java new file mode 100644 index 000000000..19103c0dd --- /dev/null +++ b/fine-joda/src/test/java/com/fr/third/joda/time/tz/ZoneInfoProviderTest.java @@ -0,0 +1,35 @@ +package com.fr.third.joda.time.tz; + +import org.junit.Test; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import static org.junit.Assert.*; + +/** + * @author Afly + * created on 2020-12-16 + */ +public class ZoneInfoProviderTest { + + @Test + public void testGetResource() throws IOException, NoSuchMethodException { + ZoneInfoProvider zoneInfoProvider = new ZoneInfoProvider(); + assertNotNull(zoneInfoProvider.getZone("Etc/GMT+8")); + Method openResource = zoneInfoProvider.getClass().getDeclaredMethod("openResource", String.class); + openResource.setAccessible(true); + try { + openResource.invoke(zoneInfoProvider, "Etc/Exception+8"); + fail(); + } catch (Exception ignored) { + } + + try { + openResource.invoke(zoneInfoProvider, "Etc/Exception-8"); + fail(); + } catch (Exception ignored) { + } + } +} \ No newline at end of file From 1b41de0e424202fb1e7723156354c4779b4ad7ef Mon Sep 17 00:00:00 2001 From: Afly Date: Thu, 17 Dec 2020 11:29:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?DEC-16125=20fix:=20=E5=B0=91=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=B8=AAGMT+12,third=E5=8C=85=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=B7=91=E4=B8=8D=E5=88=B0=EF=BC=8C=E7=A7=BB?= =?UTF-8?q?=E5=88=B0decision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third/joda/time/tz/ZoneInfoProvider.java | 1 + .../joda/time/tz/ZoneInfoProviderTest.java | 35 ------------------- 2 files changed, 1 insertion(+), 35 deletions(-) delete mode 100644 fine-joda/src/test/java/com/fr/third/joda/time/tz/ZoneInfoProviderTest.java diff --git a/fine-joda/src/main/java/com/fr/third/joda/time/tz/ZoneInfoProvider.java b/fine-joda/src/main/java/com/fr/third/joda/time/tz/ZoneInfoProvider.java index 3cddda70e..b38a0b612 100644 --- a/fine-joda/src/main/java/com/fr/third/joda/time/tz/ZoneInfoProvider.java +++ b/fine-joda/src/main/java/com/fr/third/joda/time/tz/ZoneInfoProvider.java @@ -324,6 +324,7 @@ public class ZoneInfoProvider implements Provider { GMTData.put("GMT+9", new byte[]{70, 0, 3, 45, 48, 57, 46, 46}); GMTData.put("GMT+10", new byte[]{70, 0, 3, 45, 49, 48, 44, 44}); GMTData.put("GMT+11", new byte[]{70, 0, 3, 45, 49, 49, 42, 42}); + GMTData.put("GMT+12", new byte[]{70, 0, 3, 45, 49, 50, 40, 40}); } } diff --git a/fine-joda/src/test/java/com/fr/third/joda/time/tz/ZoneInfoProviderTest.java b/fine-joda/src/test/java/com/fr/third/joda/time/tz/ZoneInfoProviderTest.java deleted file mode 100644 index 19103c0dd..000000000 --- a/fine-joda/src/test/java/com/fr/third/joda/time/tz/ZoneInfoProviderTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.fr.third.joda.time.tz; - -import org.junit.Test; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import static org.junit.Assert.*; - -/** - * @author Afly - * created on 2020-12-16 - */ -public class ZoneInfoProviderTest { - - @Test - public void testGetResource() throws IOException, NoSuchMethodException { - ZoneInfoProvider zoneInfoProvider = new ZoneInfoProvider(); - assertNotNull(zoneInfoProvider.getZone("Etc/GMT+8")); - Method openResource = zoneInfoProvider.getClass().getDeclaredMethod("openResource", String.class); - openResource.setAccessible(true); - try { - openResource.invoke(zoneInfoProvider, "Etc/Exception+8"); - fail(); - } catch (Exception ignored) { - } - - try { - openResource.invoke(zoneInfoProvider, "Etc/Exception-8"); - fail(); - } catch (Exception ignored) { - } - } -} \ No newline at end of file