Skip to content

Commit

Permalink
Java 8 is minimum.
Browse files Browse the repository at this point in the history
  • Loading branch information
joehni committed Mar 24, 2021
1 parent 8ca51ef commit 9e0b5db
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 216 deletions.
343 changes: 184 additions & 159 deletions xstream/src/java/com/thoughtworks/xstream/XStream.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2005 Joe Walnes.
* Copyright (C) 2006, 2007, 2011, 2013, 2014, 2015, 2016, 2017, 2018 XStream Committers.
* Copyright (C) 2006, 2007, 2011, 2013, 2014, 2015, 2016, 2017, 2018, 2021 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand All @@ -11,12 +11,11 @@
*/
package com.thoughtworks.xstream.converters.extended;

import java.lang.reflect.InvocationTargetException;
import java.util.GregorianCalendar;

import com.thoughtworks.xstream.converters.SingleValueConverter;
import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
import com.thoughtworks.xstream.core.JVM;
import com.thoughtworks.xstream.core.util.ISO8601JavaTimeConverter;


/**
Expand All @@ -35,22 +34,7 @@ public class ISO8601GregorianCalendarConverter extends AbstractSingleValueConver
private final SingleValueConverter converter;

public ISO8601GregorianCalendarConverter() {
SingleValueConverter svConverter = null;
final Class<? extends SingleValueConverter> type = JVM.<SingleValueConverter>loadClassForName(JVM.isVersion(8)
? "com.thoughtworks.xstream.core.util.ISO8601JavaTimeConverter"
: "com.thoughtworks.xstream.core.util.ISO8601JodaTimeConverter");
try {
svConverter = type.getDeclaredConstructor().newInstance();
} catch (final
InstantiationException
| IllegalAccessException
| IllegalArgumentException
| InvocationTargetException
| NoSuchMethodException
| SecurityException e) {
// ignore
}
converter = svConverter;
converter = new ISO8601JavaTimeConverter();
}

@Override
Expand Down
22 changes: 11 additions & 11 deletions xstream/src/java/com/thoughtworks/xstream/core/JVM.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -55,7 +55,7 @@ public class JVM implements Caching {

private static final String vendor = System.getProperty("java.vm.vendor");
private static final float majorJavaVersion = getMajorJavaVersion();
private static final float DEFAULT_JAVA_VERSION = 1.7f;
private static final float DEFAULT_JAVA_VERSION = 1.8f;
private static final boolean reverseFieldOrder = false;
private static final Class<? extends ReflectionProvider> reflectionProviderType;
@Deprecated
Expand Down Expand Up @@ -207,31 +207,31 @@ public JVM() {
*/
private static final float getMajorJavaVersion() {
try {
return isAndroid() ? 1.7f : Float.parseFloat(System.getProperty("java.specification.version"));
return isAndroid() ? 8f : Float.parseFloat(System.getProperty("java.specification.version"));
} catch (final NumberFormatException e) {
// Some JVMs may not conform to the x.y.z java.version format
return DEFAULT_JAVA_VERSION;
}
}

/**
* @deprecated As of 1.4.4, minimal JDK version is 1.4 already
* @deprecated As of 1.4.4, minimal JDK version is 1.8 already
*/
@Deprecated
public static boolean is14() {
return isVersion(4);
}

/**
* @deprecated As of 1.4.4, minimal JDK version will be 1.7 for next major release
* @deprecated As of 1.4.4, minimal JDK version is 1.8 already
*/
@Deprecated
public static boolean is15() {
return isVersion(5);
}

/**
* @deprecated As of 1.4.4, minimal JDK version will be 1.7 for next major release
* @deprecated As of 1.4.4, minimal JDK version is 1.8 already
*/
@Deprecated
public static boolean is16() {
Expand All @@ -240,7 +240,7 @@ public static boolean is16() {

/**
* @since 1.4
* @deprecated As of 1.4.10, minimal JDK version will be 1.7 for next major release
* @deprecated As of 1.4.10, minimal JDK version is 1.8 already
*/
@Deprecated
public static boolean is17() {
Expand Down Expand Up @@ -333,8 +333,8 @@ public <T> Class<? extends T> loadClass(final String name) {
public static <T> Class<? extends T> loadClassForName(final String name, final boolean initialize) {
try {
@SuppressWarnings("unchecked")
final Class<? extends T> clazz = (Class<? extends T>)Class
.forName(name, initialize, JVM.class.getClassLoader());
final Class<? extends T> clazz = (Class<? extends T>)Class.forName(name, initialize, JVM.class
.getClassLoader());
return clazz;
} catch (final LinkageError | ClassNotFoundException e) {
return null;
Expand Down Expand Up @@ -623,7 +623,7 @@ public static void main(final String... args) {
System.out.println("Can parse UTC date format: " + canParseUTCDateFormat());
System.out.println("Can create derive ObjectOutputStream: " + canCreateDerivedObjectOutputStream());
System.out.println("Reverse field order detected for JDK: " + reverseJDK);
System.out
.println("Reverse field order detected (only if JVM class itself has been compiled): " + reverseLocal);
System.out.println("Reverse field order detected (only if JVM class itself has been compiled): "
+ reverseLocal);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2005 Joe Walnes.
* Copyright (C) 2006, 2007, 2011, 2013, 2014, 2015, 2016, 2017 XStream Committers.
* Copyright (C) 2006, 2007, 2011, 2013, 2014, 2015, 2016, 2017, 2021 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -35,7 +35,9 @@
* @author J&ouml;rg Schaible
* @see <a href="http://www.iso.org/iso/home/store/catalogue_ics/catalogue_detail_ics.htm?csnumber=40874">ISO 8601</a>
* @since 1.4.10
* @deprecated As of upcoming, no longer required since Java 8, use {@link ISO8601JavaTimeConverter} instead
*/
@Deprecated
public class ISO8601JodaTimeConverter extends AbstractSingleValueConverter {
private static final DateTimeFormatter[] formattersUTC = { //
ISODateTimeFormat.dateTime(), //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012, 2015, 2017, 2018 XStream Committers.
* Copyright (C) 2012, 2015, 2017, 2018, 2021 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand All @@ -14,7 +14,6 @@
import java.util.concurrent.ConcurrentHashMap;

import com.thoughtworks.xstream.converters.collections.MapConverter;
import com.thoughtworks.xstream.core.JVM;


public class ConcurrentTypesTest extends AbstractAcceptanceTest {
Expand All @@ -40,22 +39,20 @@ public static class DerivedConcurrentHashMap extends ConcurrentHashMap<Object, O
}

public void testDerivedConcurrentHashMap() {
if (JVM.isVersion(8)) {
xstream.alias("derived-map", DerivedConcurrentHashMap.class);
xstream.registerConverter(new MapConverter(xstream.getMapper(), DerivedConcurrentHashMap.class));

final Map<Object, Object> map = new DerivedConcurrentHashMap();
map.put("test", "JUnit");

final String xml = ""
+ "<derived-map>\n"
+ " <entry>\n"
+ " <string>test</string>\n"
+ " <string>JUnit</string>\n"
+ " </entry>\n"
+ "</derived-map>";

assertBothWays(map, xml);
}
xstream.alias("derived-map", DerivedConcurrentHashMap.class);
xstream.registerConverter(new MapConverter(xstream.getMapper(), DerivedConcurrentHashMap.class));

final Map<Object, Object> map = new DerivedConcurrentHashMap();
map.put("test", "JUnit");

final String xml = ""
+ "<derived-map>\n"
+ " <entry>\n"
+ " <string>test</string>\n"
+ " <string>JUnit</string>\n"
+ " </entry>\n"
+ "</derived-map>";

assertBothWays(map, xml);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2005 Joe Walnes.
* Copyright (C) 2006, 2007, 2011, 2017, 2018 XStream Committers.
* Copyright (C) 2006, 2007, 2011, 2017, 2018, 2021 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -293,17 +293,15 @@ public void testParsesStandardDateFragment() {
expected.set(Calendar.YEAR, 2017);
Calendar out = (Calendar)converter.fromString("2017");
assertEquals(expected.getTime(), out.getTime());
if (JVM.isVersion(8)) { // Java 8 passes, Joda-Time fails
expected.set(Calendar.MONTH, 3);
out = (Calendar)converter.fromString("2017-04");
assertEquals(expected.getTime(), out.getTime());
}
expected.set(Calendar.MONTH, 3);
out = (Calendar)converter.fromString("2017-04");
assertEquals(expected.getTime(), out.getTime());
}

public void testParsesStandardWeekDateFragment() {
final Calendar expected = Calendar.getInstance();
expected.clear();
if (!JVM.isVersion(8)) { // TODO: Java 8 fails here, Joda-Time passes
if (!JVM.isVersion(8)) { // TODO: Java fails here, Joda-Time passes
expected.set(2017, 3, 17);
final Calendar out = (Calendar)converter.fromString("2017-W16");
assertEquals(expected.getTime(), out.getTime());
Expand Down

0 comments on commit 9e0b5db

Please sign in to comment.