Skip to content

Commit

Permalink
Honor Systems generated updates. Closes #296.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsujenkins authored and joehni committed Jul 3, 2022
1 parent eb21c8d commit cf61d54
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008, 2009, 2011, 2015 XStream Committers.
* Copyright (C) 2008, 2009, 2011, 2015, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -39,6 +39,6 @@ public boolean equals(Object obj) {
}

public int hashCode() {
return super.hashCode() + two + new Boolean(three).hashCode() + five.toString().hashCode();
return super.hashCode() + two + Boolean.valueOf(three).hashCode() + five.toString().hashCode();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009, 2011, 2015 XStream Committers.
* Copyright (C) 2009, 2011, 2015, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -63,6 +63,6 @@ public boolean equals(Object obj) {
}

public int hashCode() {
return super.hashCode() + two + new Boolean(three).hashCode() + five.toString().hashCode();
return super.hashCode() + two + Boolean.valueOf(three).hashCode() + five.toString().hashCode();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008, 2009, 2011, 2015 XStream Committers.
* Copyright (C) 2008, 2009, 2011, 2015, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -52,6 +52,6 @@ public boolean equals(Object obj) {
}

public int hashCode() {
return super.hashCode() + two + new Boolean(three).hashCode() + five.toString().hashCode();
return super.hashCode() + two + Boolean.valueOf(three).hashCode() + five.toString().hashCode();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008, 2009, 2011, 2015 XStream Committers.
* Copyright (C) 2008, 2009, 2011, 2015, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -31,14 +31,14 @@ public class BasicTarget implements Target {

public BasicTarget() {
list = new ArrayList();
list.add(new Integer(1));
list.add(new Byte((byte)2));
list.add(new Short((short)3));
list.add(new Long(4));
list.add(Integer.valueOf(1));
list.add(Byte.valueOf((byte)2));
list.add(Short.valueOf((short)3));
list.add(Long.valueOf(4));
list.add("Profile");
list.add(Boolean.TRUE);
list.add(new Float(1.2f));
list.add(new Double(1.2f));
list.add(Float.valueOf(1.2f));
list.add(Double.valueOf(1.2f));
list.add(new File("profile.txt"));
list.add(Locale.ENGLISH);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008, 2009, 2011, 2015 XStream Committers.
* Copyright (C) 2008, 2009, 2011, 2015, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -85,9 +85,9 @@ static class RunnableInvocationHandler implements InvocationHandler {

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.equals(EQUALS)) {
return new Boolean(args[0] instanceof Runnable);
return Boolean.valueOf(args[0] instanceof Runnable);
} else if (method.getName().equals("hashCode")) {
return new Integer(System.identityHashCode(proxy));
return Integer.valueOf(System.identityHashCode(proxy));
} else if (method.getName().equals("toString")) {
return "Proxy" + System.identityHashCode(proxy);
} else if (method.getName().equals("getClass")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, 2017, 2021 XStream Committers.
* Copyright (C) 2015, 2017, 2021, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -39,7 +39,6 @@
import com.thoughtworks.xstream.io.xml.CompactWriter;
import com.thoughtworks.xstream.io.xml.MXParserDriver;
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
import com.thoughtworks.xstream.io.xml.Xpp3Driver;
import com.thoughtworks.xstream.security.ArrayTypePermission;
import com.thoughtworks.xstream.security.NoTypePermission;

Expand Down Expand Up @@ -171,7 +170,7 @@ private ConcurrentHashMapStringConverter(final ConcurrentMap<String, String> map
* @since 1.4.9
*/
public ConcurrentHashMapStringConverter(final int lengthLimit) {
this(new ConcurrentHashMap<String, String>(), lengthLimit);
this(new ConcurrentHashMap<>(), lengthLimit);
}

@Override
Expand Down
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, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2018 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2018, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -191,7 +191,7 @@ public void writeItem(final Object item) {
};

final Map<String, Set<Mapper.ImplicitCollectionMapping>> hiddenMappers =
new HashMap<String, Set<Mapper.ImplicitCollectionMapping>>();
new HashMap<>();
for (final FieldInfo info : fields) {
if (info.value != null) {
final boolean isCollection = info.value instanceof Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2007, 2014 XStream Committers.
* Copyright (C) 2007, 2014, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand All @@ -26,7 +26,7 @@ public class NativeFieldKeySorter implements FieldKeySorter {

@Override
public Map<FieldKey, Field> sort(final Class<?> type, final Map<FieldKey, Field> keyedByFieldKey) {
final Map<FieldKey, Field> map = new TreeMap<FieldKey, Field>(new Comparator<FieldKey>() {
final Map<FieldKey, Field> map = new TreeMap<>(new Comparator<FieldKey>() {

@Override
public int compare(final FieldKey fieldKey1, final FieldKey fieldKey2) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2007, 2008, 2013, 2014 XStream Committers.
* Copyright (C) 2007, 2008, 2013, 2014, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -27,7 +27,7 @@ public class XStream12FieldKeySorter implements FieldKeySorter {

@Override
public Map<FieldKey, Field> sort(final Class<?> type, final Map<FieldKey, Field> keyedByFieldKey) {
final Map<FieldKey, Field> map = new TreeMap<FieldKey, Field>(new Comparator<FieldKey>() {
final Map<FieldKey, Field> map = new TreeMap<>(new Comparator<FieldKey>() {

@Override
public int compare(final FieldKey fieldKey1, final FieldKey fieldKey2) {
Expand Down
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, 2009, 2011, 2013, 2014, 2015, 2016, 2017, 2019 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014, 2015, 2016, 2017, 2019, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -37,7 +37,7 @@ public class DefaultConverterLookup implements ConverterLookup, ConverterRegistr
private Map<String, Converter> serializationMap = null;

public DefaultConverterLookup() {
this(new HashMap<String, Converter>());
this(new HashMap<>());
}

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ private Object writeReplace() {
}

private Object readResolve() {
typeToConverterMap = serializationMap == null ? new HashMap<String, Converter>() : serializationMap;
typeToConverterMap = serializationMap == null ? new HashMap<>() : serializationMap;
serializationMap = null;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2006, 2007, 2010, 2014, 2015 XStream Committers.
* Copyright (C) 2006, 2007, 2010, 2014, 2015, 2022 XStream Committers.
* All rights reserved.
*
* Created on 12.10.2010 by Joerg Schaible, extracted from TreeMapConverter.
Expand Down Expand Up @@ -27,11 +27,11 @@ private static class ArraySet<T> extends ArrayList<T> implements Set<T> {
private final Comparator<K> comparator;

public PresortedMap() {
this(null, new ArraySet<Map.Entry<K, V>>());
this(null, new ArraySet<>());
}

public PresortedMap(final Comparator<K> comparator) {
this(comparator, new ArraySet<Map.Entry<K, V>>());
this(comparator, new ArraySet<>());
}

private PresortedMap(final Comparator<K> comparator, final PresortedMap.ArraySet<Map.Entry<K, V>> set) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2008, 2014, 2016 XStream Committers.
* Copyright (c) 2007, 2008, 2014, 2016, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -42,7 +42,7 @@ public ThreadSafePropertyEditor(
throw new IllegalArgumentException(type.getName() + " is not a " + PropertyEditor.class.getName());
}
editorType = type;
pool = new Pool<PropertyEditor>(initialPoolSize, maxPoolSize, new Pool.Factory<PropertyEditor>() {
pool = new Pool<>(initialPoolSize, maxPoolSize, new Pool.Factory<PropertyEditor>() {
@Override
public PropertyEditor newInstance() {
ErrorWritingException ex = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2005 Joe Walnes.
* Copyright (C) 2006, 2007, 2009, 2011, 2012, 2014 XStream Committers.
* Copyright (C) 2006, 2007, 2009, 2011, 2012, 2014, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -51,7 +51,7 @@ public ThreadSafeSimpleDateFormat(
final int maxPoolSize, final boolean lenient) {
formatString = format;
this.timeZone = timeZone;
pool = new Pool<DateFormat>(initialPoolSize, maxPoolSize, new Pool.Factory<DateFormat>() {
pool = new Pool<>(initialPoolSize, maxPoolSize, new Pool.Factory<DateFormat>() {
@Override
public SimpleDateFormat newInstance() {
final SimpleDateFormat dateFormat = new SimpleDateFormat(formatString, locale);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011, 2013, 2014, 2015, 2019 XStream Committers.
* Copyright (C) 2011, 2013, 2014, 2015, 2019, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -42,7 +42,7 @@ public class WeakCache<K, V> extends AbstractMap<K, V> {
* @since 1.4
*/
public WeakCache() {
this(new WeakHashMap<K, Reference<V>>());
this(new WeakHashMap<>());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2014, 2015 XStream Committers.
* Copyright (C) 2006, 2007, 2014, 2015, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -97,7 +97,7 @@ private void startNodeCommon() {
}
state = STATE_NODE_START;
++balance;
attributes.push(new HashSet<String>());
attributes.push(new HashSet<>());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2014, 2018 XStream Committers.
* Copyright (c) 2008, 2009, 2010, 2011, 2014, 2018, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -38,7 +38,7 @@
public class JettisonStaxWriter extends StaxWriter {

private final MappedNamespaceConvention convention;
private final Deque<String> stack = new ArrayDeque<String>();
private final Deque<String> stack = new ArrayDeque<>();

/**
* @since 1.4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004 Joe Walnes.
* Copyright (C) 2006, 2007, 2013, 2014, 2015, 2020 XStream Committers.
* Copyright (C) 2006, 2007, 2013, 2014, 2015, 2020, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -286,7 +286,7 @@ public void setSourceAsList(final List<?> list) {
}
@SuppressWarnings("unchecked")
final List<Object> olist = (List<Object>)list;
source = list instanceof Queue ? (Queue<?>)list : new ListWrappingQueue<Object>(olist);
source = list instanceof Queue ? (Queue<?>)list : new ListWrappingQueue<>(olist);

configureXMLReader();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2016 XStream Committers.
* Copyright (C) 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2016, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -289,8 +289,8 @@ private void processConverterAnnotations(final Class<?> type) {
final XStreamConverters convertersAnnotation = type.getAnnotation(XStreamConverters.class);
final XStreamConverter converterAnnotation = type.getAnnotation(XStreamConverter.class);
final List<XStreamConverter> annotations = convertersAnnotation != null
? new ArrayList<XStreamConverter>(Arrays.asList(convertersAnnotation.value()))
: new ArrayList<XStreamConverter>();
? new ArrayList<>(Arrays.asList(convertersAnnotation.value()))
: new ArrayList<>();
if (converterAnnotation != null) {
annotations.add(converterAnnotation);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014, 2015 XStream Committers.
* Copyright (C) 2014, 2015, 2022 XStream Committers.
* All rights reserved.
*
* Created on 08. January 2014 by Joerg Schaible
Expand Down Expand Up @@ -47,8 +47,8 @@ public SecurityMapper(final Mapper wrapped) {
public SecurityMapper(final Mapper wrapped, final TypePermission... permissions) {
super(wrapped);
this.permissions = permissions == null //
? new ArrayList<TypePermission>()
: new ArrayList<TypePermission>(Arrays.asList(permissions));
? new ArrayList<>()
: new ArrayList<>(Arrays.asList(permissions));
}

/**
Expand Down

4 comments on commit cf61d54

@aweseeker
Copy link

@aweseeker aweseeker commented on cf61d54 May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In JettisonStaxWriter.java under com.thoughtworks.xstream.io.json package in xstream 1.4.19 version, there is a method startNode( ) defined with following (whole startNode( ) method section) logic, however I couldn't trace one particular change within this method. I verified till old history commits(10 yrs ago), but I dont see below change(No trace for below change section), only I could see is it was calling deprecated method in old commits ((AbstractXMLStreamWriter)out).seriliazeAsArray(key); and in recent updates it was completely removed(as in this current commit). All I want know is why there is check if(!JVM.is15()) for getSerializedAsArrays(), so I wanted to check history commits but couldnt find any for this change. Anyhelp is appreciated .

No trace for below change:

if (!JVM.is15()) {
                 final ArrayList serializedAsArrays = ((AbstractXMLStreamWriter)out).getSerializedAsArrays();
                 if (!serializedAsArrays.contains(key)) {
                     serializedAsArrays.add(key);
                 }
                 key = "";
             }

Whole startNode( ) method

public void startNode(final String name, final Class clazz) {
       final XMLStreamWriter out = getXMLStreamWriter();
       String key = "";
       if (clazz != null && out instanceof AbstractXMLStreamWriter) {
           if (Collection.class.isAssignableFrom(clazz) || Map.class.isAssignableFrom(clazz) || clazz.isArray()) {
               final QName qname = getQNameMap().getQName(encodeNode(name));
               final String prefix = qname.getPrefix();
               final String uri = qname.getNamespaceURI();
               key = convention.createKey(prefix, uri, qname.getLocalPart());

               if (!JVM.is15()) {
                   final ArrayList serializedAsArrays = ((AbstractXMLStreamWriter)out).getSerializedAsArrays();
                   if (!serializedAsArrays.contains(key)) {
                       serializedAsArrays.add(key);
                   }
                   key = "";
               }
           }
       }
       stack.add(key);
       super.startNode(name);
   }

@joehni
Copy link
Member

@joehni joehni commented on cf61d54 May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is executed in XStream 1.4.19 if you run it with Java 1.4 and Jettison 1.0.1. It was removed on the master branch, since Java 1.4 is no longer supported as runtime environment.

@aweseeker
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @joehni , May I know if there is any issue if we execute the block (!JVM.is15()) in higher version like Java 8 or above(we can comment this if condition). We have dependency with "serializedAsArrays" content, we need put an arraylist element in serializedAsArrays and based on its presence we determine data type of its sub element.

For example (expected):
"factProperties":{"factProperty":[{"name":"offerCallBack","description":"","type":"JAVA_CLASS","javaClass":"java.lang.Boolean","sensitive":false},{"name":"test6","description":"","type":"STRING","sensitive":false},{"name":"test8","description":"","type":"STRING","sensitive":false}]}

Example description: We need to put "factProperties" in serializedArrays(dataType is ArrayList), and based on its presence in serializedAsArrays we determine its subelement ''factProperty'' dataType as ''array'' otherwise it will be treated as plain Obejct. Since in xstream .19 it comes under with condition (!JVM.is15()), we couldnt put it in serializedArrays as we use Java 8, we can remove (!JVM.is15()) condition in our implementation, but would want to know why this condition is particularly specified for executing this block in lower java(1.4)env, any harm if we execute in higher environment ?

@joehni
Copy link
Member

@joehni joehni commented on cf61d54 May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that block is required for Jettison 1.0.1. For all support Jettison versions it is not required, because the implementation of the JettisonStaxDriver keeps track of types that are JSON lists (see usage of "stack" in startNode/endNode). Mapping of XML to JSON is not possible 1:1 and Jettison uses some heuristics to detect JSON arrays simply derived from the structure of the processed XML. XStream's driver implementation is tweaked to allow deserialization in a lot of cases - see the JettisonStaxDriverTest of the 1.4.x branch about the differences in the JSON format Jettison produces with its heuristic. Since Jettison 1.4.1 you'll need an additional configuration setting (see code in master branch), Jettison 1.2.1 to 1.4.0 (inclusive) won't work at all properly. If you modify something, run the unit tests against it to see what corner case you're failing then.

Please sign in to comment.