undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
87
test/jdk/java/beans/XMLDecoder/4676532/Test4676532.java
Normal file
87
test/jdk/java/beans/XMLDecoder/4676532/Test4676532.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4676532
|
||||
* @summary Tests XMLDecoder.setClassLoader()
|
||||
* @author Mark Davidson
|
||||
*/
|
||||
|
||||
import java.beans.ExceptionListener;
|
||||
import java.beans.XMLDecoder;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
/**
|
||||
* Tests the XMLDecoder with an alternative classloader.
|
||||
* Specicifically, the URLClassLoader.
|
||||
* The test.jar file should be in the same directory as the classes.
|
||||
* The Encode class will create the test.xml test file.
|
||||
*/
|
||||
public class Test4676532 {
|
||||
private static final String DATA
|
||||
= "<java>\n"
|
||||
+ " <object class=\"test.Test\">\n"
|
||||
+ " <void property=\"message\">\n"
|
||||
+ " <string>Hello, world</string>\n"
|
||||
+ " </void>\n"
|
||||
+ " </object>\n"
|
||||
+ "</java> ";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
StringBuilder sb = new StringBuilder(256);
|
||||
sb.append("file:");
|
||||
sb.append(System.getProperty("test.src", "."));
|
||||
sb.append(File.separatorChar);
|
||||
sb.append("test.jar");
|
||||
|
||||
URL[] url = {new URL(sb.toString())};
|
||||
URLClassLoader cl = new URLClassLoader(url);
|
||||
|
||||
Class type = cl.loadClass("test.Test");
|
||||
if (type == null) {
|
||||
throw new Error("could not find class test.Test");
|
||||
}
|
||||
|
||||
|
||||
InputStream stream = new ByteArrayInputStream(DATA.getBytes());
|
||||
|
||||
ExceptionListener el = new ExceptionListener() {
|
||||
public void exceptionThrown(Exception exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
};
|
||||
|
||||
XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
|
||||
Object object = decoder.readObject();
|
||||
decoder.close();
|
||||
|
||||
if (!type.equals(object.getClass())) {
|
||||
throw new Error("unexpected " + object.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
test/jdk/java/beans/XMLDecoder/4676532/test.jar
Normal file
BIN
test/jdk/java/beans/XMLDecoder/4676532/test.jar
Normal file
Binary file not shown.
143
test/jdk/java/beans/XMLDecoder/8028054/Task.java
Normal file
143
test/jdk/java/beans/XMLDecoder/8028054/Task.java
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.FileSystemNotFoundException;
|
||||
import java.nio.file.ProviderNotFoundException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
abstract class Task<T> implements Runnable {
|
||||
private transient boolean working = true;
|
||||
private final List<T> methods;
|
||||
private final Thread thread;
|
||||
|
||||
Task(List<T> methods) {
|
||||
this.methods = methods;
|
||||
this.thread = new Thread(this);
|
||||
this.thread.start();
|
||||
}
|
||||
|
||||
boolean isAlive() {
|
||||
return this.thread.isAlive();
|
||||
}
|
||||
|
||||
boolean isWorking() {
|
||||
boolean working = this.working && this.thread.isAlive();
|
||||
this.working = false;
|
||||
return working;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long time = -System.currentTimeMillis();
|
||||
for (T method : this.methods) {
|
||||
this.working = true;
|
||||
try {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
process(method);
|
||||
}
|
||||
} catch (NoSuchMethodException ignore) {
|
||||
}
|
||||
}
|
||||
time += System.currentTimeMillis();
|
||||
print("thread done in " + time / 1000 + " seconds");
|
||||
}
|
||||
|
||||
protected abstract void process(T method) throws NoSuchMethodException;
|
||||
|
||||
static synchronized void print(Object message) {
|
||||
System.out.println(message);
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
static List<Class<?>> getClasses(int count) throws Exception {
|
||||
List<Class<?>> classes = new ArrayList<>();
|
||||
FileSystem fs = null;
|
||||
|
||||
try {
|
||||
fs = FileSystems.getFileSystem(URI.create("jrt:/"));
|
||||
} catch (ProviderNotFoundException | FileSystemNotFoundException e) {
|
||||
throw new RuntimeException("FAIL - JRT Filesystem not found");
|
||||
}
|
||||
|
||||
List<String> fileNames;
|
||||
Path modules = fs.getPath("/modules");
|
||||
|
||||
Predicate<String> startsWithJavaBase = path -> path.toString().startsWith("java.base/java");
|
||||
Predicate<String> startsWithJavaDesktop = path -> path.toString().startsWith("java.desktop/java");
|
||||
Predicate<String> startsWithJavaDataTransfer = path -> path.toString().startsWith("java.datatransfer/java");
|
||||
Predicate<String> startsWithJavaRMI = path -> path.toString().startsWith("java.rmi/java");
|
||||
Predicate<String> startsWithJavaSmartCardIO = path -> path.toString().startsWith("java.smartcardio/java");
|
||||
Predicate<String> startsWithJavaManagement = path -> path.toString().startsWith("java.management/java");
|
||||
Predicate<String> startsWithJavaXML = path -> path.toString().startsWith("java.xml/java");
|
||||
Predicate<String> startsWithJavaScripting = path -> path.toString().startsWith("java.scripting/java");
|
||||
Predicate<String> startsWithJavaNaming = path -> path.toString().startsWith("java.naming/java");
|
||||
Predicate<String> startsWithJavaSQL = path -> path.toString().startsWith("java.sql/java");
|
||||
Predicate<String> startsWithJavaCompiler = path -> path.toString().startsWith("java.compiler/java");
|
||||
Predicate<String> startsWithJavaLogging = path -> path.toString().startsWith("java.logging/java");
|
||||
Predicate<String> startsWithJavaPrefs = path -> path.toString().startsWith("java.prefs/java");
|
||||
|
||||
fileNames = Files.walk(modules)
|
||||
.map(Path::toString)
|
||||
.filter(path -> path.toString().contains("java"))
|
||||
.map(s -> s.substring(9)) // remove /modules/ from beginning
|
||||
.filter(startsWithJavaBase
|
||||
.or(startsWithJavaDesktop)
|
||||
.or(startsWithJavaDataTransfer)
|
||||
.or(startsWithJavaRMI)
|
||||
.or(startsWithJavaSmartCardIO)
|
||||
.or(startsWithJavaManagement)
|
||||
.or(startsWithJavaXML)
|
||||
.or(startsWithJavaScripting)
|
||||
.or(startsWithJavaNaming)
|
||||
.or(startsWithJavaSQL)
|
||||
.or(startsWithJavaCompiler)
|
||||
.or(startsWithJavaLogging)
|
||||
.or(startsWithJavaPrefs))
|
||||
.map(s -> s.replace('/', '.'))
|
||||
.filter(path -> path.toString().endsWith(".class"))
|
||||
.map(s -> s.substring(0, s.length() - 6)) // drop .class
|
||||
.map(s -> s.substring(s.indexOf(".")))
|
||||
.filter(path -> path.toString().contains("java"))
|
||||
.map(s -> s.substring(s.indexOf("java")))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||
for (String name : fileNames) {
|
||||
classes.add(Class.forName(name, false, scl));
|
||||
if (count == classes.size()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import com.sun.beans.finder.ConstructorFinder;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8028054
|
||||
* @summary Tests that cached constructors have synchronized access
|
||||
* @author Sergey Malenkov
|
||||
* @modules java.desktop/com.sun.beans.finder
|
||||
* @compile -XDignore.symbol.file TestConstructorFinder.java
|
||||
* @run main TestConstructorFinder
|
||||
*/
|
||||
|
||||
public class TestConstructorFinder {
|
||||
public static void main(String[] args) throws Exception {
|
||||
List<Class<?>> classes = Task.getClasses(Integer.MAX_VALUE);
|
||||
List<Constructor> constructors = new ArrayList<>();
|
||||
for (Class<?> type : classes) {
|
||||
Collections.addAll(constructors, type.getConstructors());
|
||||
}
|
||||
Task.print("found " + constructors.size() + " constructors in " + classes.size() + " classes");
|
||||
|
||||
List<Task> tasks = new ArrayList<>();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
tasks.add(new Task<Constructor>(constructors) {
|
||||
@Override
|
||||
protected void process(Constructor constructor) throws NoSuchMethodException {
|
||||
ConstructorFinder.findConstructor(constructor.getDeclaringClass(), constructor.getParameterTypes());
|
||||
}
|
||||
});
|
||||
}
|
||||
int alarm = 0;
|
||||
while (true) {
|
||||
int alive = 0;
|
||||
int working = 0;
|
||||
for (Task task : tasks) {
|
||||
if (task.isWorking()) {
|
||||
working++;
|
||||
alive++;
|
||||
} else if (task.isAlive()) {
|
||||
alive++;
|
||||
}
|
||||
}
|
||||
if (alive == 0) {
|
||||
break;
|
||||
}
|
||||
Task.print(working + " out of " + alive + " threads are working");
|
||||
if ((working == 0) && (++alarm == 10)) {
|
||||
throw new RuntimeException("FAIL - DEADLOCK DETECTED");
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
81
test/jdk/java/beans/XMLDecoder/8028054/TestMethodFinder.java
Normal file
81
test/jdk/java/beans/XMLDecoder/8028054/TestMethodFinder.java
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import com.sun.beans.finder.MethodFinder;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8028054
|
||||
* @summary Tests that cached methods have synchronized access
|
||||
* @author Sergey Malenkov
|
||||
* @modules java.desktop/com.sun.beans.finder
|
||||
* @compile -XDignore.symbol.file TestMethodFinder.java
|
||||
* @run main/timeout=480 TestMethodFinder
|
||||
*/
|
||||
|
||||
public class TestMethodFinder {
|
||||
public static void main(String[] args) throws Exception {
|
||||
List<Class<?>> classes = Task.getClasses(4000);
|
||||
List<Method> methods = new ArrayList<>();
|
||||
for (Class<?> type : classes) {
|
||||
Collections.addAll(methods, type.getMethods());
|
||||
}
|
||||
Task.print("found " + methods.size() + " methods in " + classes.size() + " classes");
|
||||
|
||||
List<Task> tasks = new ArrayList<>();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
tasks.add(new Task<Method>(methods) {
|
||||
@Override
|
||||
protected void process(Method method) throws NoSuchMethodException {
|
||||
MethodFinder.findMethod(method.getDeclaringClass(), method.getName(), method.getParameterTypes());
|
||||
}
|
||||
});
|
||||
}
|
||||
int alarm = 0;
|
||||
while (true) {
|
||||
int alive = 0;
|
||||
int working = 0;
|
||||
for (Task task : tasks) {
|
||||
if (task.isWorking()) {
|
||||
working++;
|
||||
alive++;
|
||||
} else if (task.isAlive()) {
|
||||
alive++;
|
||||
}
|
||||
}
|
||||
if (alive == 0) {
|
||||
break;
|
||||
}
|
||||
Task.print(working + " out of " + alive + " threads are working");
|
||||
if ((working == 0) && (++alarm == 10)) {
|
||||
throw new RuntimeException("FAIL - DEADLOCK DETECTED");
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
146
test/jdk/java/beans/XMLDecoder/Test4864117.java
Normal file
146
test/jdk/java/beans/XMLDecoder/Test4864117.java
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4864117
|
||||
* @summary Tests XMLDecoder within another DefaultHandler for SAX parser
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
import java.beans.ExceptionListener;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
public final class Test4864117 extends DefaultHandler implements ExceptionListener {
|
||||
private static final String TEST = "test";
|
||||
private static final String DATA
|
||||
= "<test>\n"
|
||||
+ " <void property=\"message\">\n"
|
||||
+ " <string>Hello, world!</string>\n"
|
||||
+ " </void>\n"
|
||||
+ "</test>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Test4864117 test = new Test4864117();
|
||||
InputStream input = new ByteArrayInputStream(DATA.getBytes());
|
||||
Exception error = null;
|
||||
try {
|
||||
SAXParserFactory.newInstance().newSAXParser().parse(input, test);
|
||||
}
|
||||
catch (ParserConfigurationException exception) {
|
||||
error = exception;
|
||||
}
|
||||
catch (SAXException exception) {
|
||||
error = exception.getException();
|
||||
if (error == null) {
|
||||
error = exception;
|
||||
}
|
||||
}
|
||||
catch (IOException exception) {
|
||||
error = exception;
|
||||
}
|
||||
if (error != null) {
|
||||
throw new Error("unexpected error", error);
|
||||
}
|
||||
test.print('?', test.getMessage());
|
||||
}
|
||||
|
||||
private String message;
|
||||
|
||||
public String getMessage() {
|
||||
if (this.message == null) {
|
||||
throw new Error("owner's method is not called");
|
||||
}
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
print(':', this.message);
|
||||
}
|
||||
|
||||
// DefaultHandler implementation
|
||||
|
||||
private DefaultHandler handler;
|
||||
private int depth;
|
||||
|
||||
@Override
|
||||
public void startDocument() throws SAXException {
|
||||
this.handler = XMLDecoder.createHandler(this, this, null);
|
||||
this.handler.startDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endDocument() {
|
||||
this.handler = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
print('>', qName);
|
||||
if (this.depth > 0) {
|
||||
this.handler.startElement(uri, localName, qName, attributes);
|
||||
} else if (!TEST.equals(qName)) {
|
||||
throw new SAXException("unexpected element name: " + qName);
|
||||
}
|
||||
this.depth++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
this.depth--;
|
||||
print('<', qName);
|
||||
if (this.depth > 0) {
|
||||
this.handler.endElement(uri, localName, qName);
|
||||
} else if (!TEST.equals(qName)) {
|
||||
throw new SAXException("unexpected element name: " + qName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
this.handler.characters(ch, start, length);
|
||||
}
|
||||
|
||||
public void exceptionThrown(Exception exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
|
||||
private void print(char ch, String name) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < this.depth; i++) sb.append(' ');
|
||||
sb.append(ch).append(' ').append(name);
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
}
|
||||
60
test/jdk/java/beans/XMLDecoder/Test6338070.java
Normal file
60
test/jdk/java/beans/XMLDecoder/Test6338070.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6338070
|
||||
* @summary Tests that parsing is performed even if readObject() is not called
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Test6338070 {
|
||||
private static final String DATA
|
||||
= "<java>\n"
|
||||
+ " <void property=\"owner\">\n"
|
||||
+ " <void method=\"init\">\n"
|
||||
+ " <string>Hello, world</string>\n"
|
||||
+ " </void>\n"
|
||||
+ " </void>\n"
|
||||
+ "</java> ";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Test6338070 test = new Test6338070();
|
||||
InputStream stream = new ByteArrayInputStream(DATA.getBytes());
|
||||
new XMLDecoder(stream, test).close();
|
||||
if (test.message == null) {
|
||||
throw new Error("owner's method is not called");
|
||||
}
|
||||
}
|
||||
|
||||
private String message;
|
||||
|
||||
public void init(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
87
test/jdk/java/beans/XMLDecoder/Test6341798.java
Normal file
87
test/jdk/java/beans/XMLDecoder/Test6341798.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6341798
|
||||
* @summary Tests name generation for turkish locale
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Locale;
|
||||
|
||||
import static java.util.Locale.ENGLISH;
|
||||
|
||||
public class Test6341798 {
|
||||
private static final Locale TURKISH = Locale.of("tr");
|
||||
|
||||
private static final String DATA
|
||||
= "<java>\n"
|
||||
+ " <object class=\"Test6341798$DataBean\">\n"
|
||||
+ " <void property=\"illegal\">\n"
|
||||
+ " <boolean>true</boolean>\n"
|
||||
+ " </void>\n"
|
||||
+ " </object>\n"
|
||||
+ "</java> ";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Locale reservedLocale = Locale.getDefault();
|
||||
try {
|
||||
test(ENGLISH, DATA.getBytes());
|
||||
test(TURKISH, DATA.getBytes());
|
||||
} finally {
|
||||
// restore the reserved locale
|
||||
Locale.setDefault(reservedLocale);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Locale locale, byte[] data) {
|
||||
Locale.setDefault(locale);
|
||||
System.out.println("locale = " + locale);
|
||||
|
||||
XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(data));
|
||||
System.out.println("object = " + decoder.readObject());
|
||||
decoder.close();
|
||||
}
|
||||
|
||||
public static class DataBean {
|
||||
private boolean illegal;
|
||||
|
||||
public boolean isIllegal() {
|
||||
return this.illegal;
|
||||
}
|
||||
|
||||
public void setIllegal(boolean illegal) {
|
||||
this.illegal = illegal;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (this.illegal) {
|
||||
return "property is set";
|
||||
}
|
||||
throw new Error("property is not set");
|
||||
}
|
||||
}
|
||||
}
|
||||
69
test/jdk/java/beans/XMLDecoder/spec/AbstractTest.java
Normal file
69
test/jdk/java/beans/XMLDecoder/spec/AbstractTest.java
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.beans.ExceptionListener;
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
abstract class AbstractTest implements ExceptionListener {
|
||||
public void exceptionThrown(Exception exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the XML decoder for XML archive
|
||||
* that defined in the public field of the subclass.
|
||||
*
|
||||
* @param decoder the initialized XML decoder
|
||||
* @throws Error if validation failed
|
||||
*/
|
||||
protected abstract void validate(XMLDecoder decoder);
|
||||
|
||||
/**
|
||||
* This is entry point to start testing.
|
||||
*/
|
||||
final void test() {
|
||||
byte[] array = getFieldValue("XML").getBytes(); // NON-NLS: the field name
|
||||
ByteArrayInputStream input = new ByteArrayInputStream(array);
|
||||
XMLDecoder decoder = new XMLDecoder(input);
|
||||
decoder.setExceptionListener(this);
|
||||
validate(decoder);
|
||||
try {
|
||||
throw new Error("unexpected object" + decoder.readObject());
|
||||
} catch (ArrayIndexOutOfBoundsException exception) {
|
||||
// expected exception
|
||||
}
|
||||
decoder.close();
|
||||
}
|
||||
|
||||
private String getFieldValue(String field) {
|
||||
try {
|
||||
return getClass().getField(field).get(this).toString();
|
||||
} catch (NoSuchFieldException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
} catch (IllegalAccessException exception) {
|
||||
throw new Error("unexpected exception", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
87
test/jdk/java/beans/XMLDecoder/spec/TestArray.java
Normal file
87
test/jdk/java/beans/XMLDecoder/spec/TestArray.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <array> element
|
||||
* @run main/othervm TestArray
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
public final class TestArray extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <array class=\"java.lang.Number\">\n"
|
||||
+ " <byte>-111</byte>\n"
|
||||
+ " <long>1111</long>\n"
|
||||
+ " </array>\n"
|
||||
+ " <array length=\"3\">\n"
|
||||
+ " <void index=\"1\">\n"
|
||||
+ " <string>Hello, world!</string>\n"
|
||||
+ " </void>\n"
|
||||
+ " </array>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestArray().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
Number[] numbers = getArray(Number.class, 2, decoder.readObject());
|
||||
if (!numbers[0].equals(Byte.valueOf("-111"))) { // NON-NLS: hardcoded in XML
|
||||
throw new Error("unexpected byte value");
|
||||
}
|
||||
if (!numbers[1].equals(Long.valueOf("1111"))) { // NON-NLS: hardcoded in XML
|
||||
throw new Error("unexpected long value");
|
||||
}
|
||||
|
||||
Object[] objects = getArray(Object.class, 3, decoder.readObject());
|
||||
if (objects[0] != null) {
|
||||
throw new Error("unexpected first value");
|
||||
}
|
||||
if (!objects[1].equals("Hello, world!")) { // NON-NLS: hardcoded in XML
|
||||
throw new Error("unexpected string value");
|
||||
}
|
||||
if (objects[2] != null) {
|
||||
throw new Error("unexpected last value");
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T[] getArray(Class<T> component, int length, Object object) {
|
||||
Class type = object.getClass();
|
||||
if (!type.isArray()) {
|
||||
throw new Error("array expected");
|
||||
}
|
||||
if (!type.getComponentType().equals(component)) {
|
||||
throw new Error("unexpected component type");
|
||||
}
|
||||
if (length != Array.getLength(object)) {
|
||||
throw new Error("unexpected array length");
|
||||
}
|
||||
return (T[]) object;
|
||||
}
|
||||
}
|
||||
53
test/jdk/java/beans/XMLDecoder/spec/TestBoolean.java
Normal file
53
test/jdk/java/beans/XMLDecoder/spec/TestBoolean.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <boolean> element
|
||||
* @run main/othervm TestBoolean
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestBoolean extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <boolean>true</boolean>\n"
|
||||
+ " <boolean>false</boolean>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestBoolean().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
if (!Boolean.TRUE.equals(decoder.readObject())) {
|
||||
throw new Error("true expected");
|
||||
}
|
||||
if (!Boolean.FALSE.equals(decoder.readObject())) {
|
||||
throw new Error("false expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
57
test/jdk/java/beans/XMLDecoder/spec/TestByte.java
Normal file
57
test/jdk/java/beans/XMLDecoder/spec/TestByte.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <byte> element
|
||||
* @run main/othervm TestByte
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestByte extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <byte>0</byte>\n"
|
||||
+ " <byte>127</byte>\n"
|
||||
+ " <byte>-128</byte>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestByte().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate((byte) 0, decoder.readObject());
|
||||
validate(Byte.MAX_VALUE, decoder.readObject());
|
||||
validate(Byte.MIN_VALUE, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(byte value, Object object) {
|
||||
if (!object.equals(Byte.valueOf(value))) {
|
||||
throw new Error("byte " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
53
test/jdk/java/beans/XMLDecoder/spec/TestChar.java
Normal file
53
test/jdk/java/beans/XMLDecoder/spec/TestChar.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <char> element
|
||||
* @run main/othervm TestChar
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestChar extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <char>X</char>\n"
|
||||
+ " <char code=\"#20\"/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestChar().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
if (!decoder.readObject().equals(Character.valueOf('X'))) {
|
||||
throw new Error("unexpected character");
|
||||
}
|
||||
if (!decoder.readObject().equals(Character.valueOf((char) 0x20))) {
|
||||
throw new Error("unexpected character code");
|
||||
}
|
||||
}
|
||||
}
|
||||
62
test/jdk/java/beans/XMLDecoder/spec/TestClass.java
Normal file
62
test/jdk/java/beans/XMLDecoder/spec/TestClass.java
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <class> element
|
||||
* @run main/othervm TestClass
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestClass extends AbstractTest {
|
||||
public static final String PREFIX = "javax.swing.colorchooser.";
|
||||
public static final String INTERFACE = "ColorSelectionModel";
|
||||
public static final String PUBLIC_CLASS = "DefaultColorSelectionModel";
|
||||
public static final String PRIVATE_CLASS = "DiagramComponent";
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <class>" + PREFIX + INTERFACE + "</class>\n"
|
||||
+ " <class>" + PREFIX + PUBLIC_CLASS + "</class>\n"
|
||||
+ " <class>" + PREFIX + PRIVATE_CLASS + "</class>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestClass().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(PREFIX + INTERFACE, decoder.readObject());
|
||||
validate(PREFIX + PUBLIC_CLASS, decoder.readObject());
|
||||
validate(PREFIX + PRIVATE_CLASS, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(String name, Object object) {
|
||||
Class type = (Class) object;
|
||||
if (!type.getName().equals(name)) {
|
||||
throw new Error(name + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
59
test/jdk/java/beans/XMLDecoder/spec/TestDouble.java
Normal file
59
test/jdk/java/beans/XMLDecoder/spec/TestDouble.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <double> element
|
||||
* @run main/othervm TestDouble
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestDouble extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <double>0</double>\n"
|
||||
+ " <double>1000</double>\n"
|
||||
+ " <double>-1.1e15</double>\n"
|
||||
+ " <double>10.11e-123</double>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestDouble().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(0.0, decoder.readObject());
|
||||
validate(1000.0, decoder.readObject());
|
||||
validate(-1.1e15, decoder.readObject());
|
||||
validate(10.11e-123, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(double value, Object object) {
|
||||
if (!object.equals(Double.valueOf(value))) {
|
||||
throw new Error("double " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
49
test/jdk/java/beans/XMLDecoder/spec/TestFalse.java
Normal file
49
test/jdk/java/beans/XMLDecoder/spec/TestFalse.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <false> element
|
||||
* @run main/othervm TestFalse
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestFalse extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <false/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestFalse().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
if (!Boolean.FALSE.equals(decoder.readObject())) {
|
||||
throw new Error("false expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
75
test/jdk/java/beans/XMLDecoder/spec/TestField.java
Normal file
75
test/jdk/java/beans/XMLDecoder/spec/TestField.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <field> element
|
||||
* @run main/othervm TestField
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestField extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <field name=\"FIELD\" class=\"TestField\"/>\n"
|
||||
+ " <field name=\"FIELD\" class=\"TestField\">\n"
|
||||
+ " <string>static postfix</string>\n"
|
||||
+ " </field>\n"
|
||||
+ " <field name=\"FIELD\" class=\"TestField\"/>\n"
|
||||
+ " <property name=\"owner\">\n"
|
||||
+ " <field id=\"prefix\" name=\"field\"/>\n"
|
||||
+ " <field name=\"field\">\n"
|
||||
+ " <string>postfix</string>\n"
|
||||
+ " </field>\n"
|
||||
+ " <field id=\"postfix\" name=\"field\"/>\n"
|
||||
+ " </property>\n"
|
||||
+ " <var idref=\"prefix\"/>\n"
|
||||
+ " <var idref=\"postfix\"/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestField().test();
|
||||
}
|
||||
|
||||
public static String FIELD;
|
||||
public String field;
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
FIELD = "static prefix";
|
||||
field = "prefix";
|
||||
decoder.setOwner(this);
|
||||
validate(decoder, "static prefix");
|
||||
validate(decoder, "static postfix");
|
||||
validate(decoder, "prefix");
|
||||
validate(decoder, "postfix");
|
||||
}
|
||||
|
||||
private static void validate(XMLDecoder decoder, String name) {
|
||||
if (!decoder.readObject().equals(name)) {
|
||||
throw new Error(name + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
59
test/jdk/java/beans/XMLDecoder/spec/TestFloat.java
Normal file
59
test/jdk/java/beans/XMLDecoder/spec/TestFloat.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <float> element
|
||||
* @run main/othervm TestFloat
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestFloat extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <float>0</float>\n"
|
||||
+ " <float>100</float>\n"
|
||||
+ " <float>-1e15</float>\n"
|
||||
+ " <float>100e-20</float>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestFloat().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(0.0f, decoder.readObject());
|
||||
validate(100.0f, decoder.readObject());
|
||||
validate(-1e15f, decoder.readObject());
|
||||
validate(100e-20f, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(float value, Object object) {
|
||||
if (!object.equals(Float.valueOf(value))) {
|
||||
throw new Error("float " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
65
test/jdk/java/beans/XMLDecoder/spec/TestInt.java
Normal file
65
test/jdk/java/beans/XMLDecoder/spec/TestInt.java
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <int> element
|
||||
* @run main/othervm TestInt
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestInt extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <int>0</int>\n"
|
||||
+ " <int>127</int>\n"
|
||||
+ " <int>-128</int>\n"
|
||||
+ " <int>32767</int>\n"
|
||||
+ " <int>-32768</int>\n"
|
||||
+ " <int>2147483647</int>\n"
|
||||
+ " <int>-2147483648</int>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestInt().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(0, decoder.readObject());
|
||||
validate((int) Byte.MAX_VALUE, decoder.readObject());
|
||||
validate((int) Byte.MIN_VALUE, decoder.readObject());
|
||||
validate((int) Short.MAX_VALUE, decoder.readObject());
|
||||
validate((int) Short.MIN_VALUE, decoder.readObject());
|
||||
validate(Integer.MAX_VALUE, decoder.readObject());
|
||||
validate(Integer.MIN_VALUE, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(int value, Object object) {
|
||||
if (!object.equals(Integer.valueOf(value))) {
|
||||
throw new Error("int " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
64
test/jdk/java/beans/XMLDecoder/spec/TestJava.java
Normal file
64
test/jdk/java/beans/XMLDecoder/spec/TestJava.java
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <java> element
|
||||
* @run main/othervm TestJava
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestJava extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <void id=\"owner\" method=\"getOwner\">\n"
|
||||
+ " <void method=\"init\">\n"
|
||||
+ " <string>Hello, world!</string>\n"
|
||||
+ " </void>\n"
|
||||
+ " </void>\n"
|
||||
+ " <object idref=\"owner\"/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestJava().test();
|
||||
}
|
||||
|
||||
private String message;
|
||||
|
||||
public void init(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
decoder.setOwner(this);
|
||||
if (this != decoder.readObject()) {
|
||||
throw new Error("owner should be the same");
|
||||
}
|
||||
if (this.message == null) {
|
||||
throw new Error("owner's method is not called");
|
||||
}
|
||||
}
|
||||
}
|
||||
69
test/jdk/java/beans/XMLDecoder/spec/TestLong.java
Normal file
69
test/jdk/java/beans/XMLDecoder/spec/TestLong.java
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <long> element
|
||||
* @run main/othervm TestLong
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestLong extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <long>0</long>\n"
|
||||
+ " <long>127</long>\n"
|
||||
+ " <long>-128</long>\n"
|
||||
+ " <long>32767</long>\n"
|
||||
+ " <long>-32768</long>\n"
|
||||
+ " <long>2147483647</long>\n"
|
||||
+ " <long>-2147483648</long>\n"
|
||||
+ " <long>9223372036854775807</long>\n"
|
||||
+ " <long>-9223372036854775808</long>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestLong().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(0L, decoder.readObject());
|
||||
validate((long) Byte.MAX_VALUE, decoder.readObject());
|
||||
validate((long) Byte.MIN_VALUE, decoder.readObject());
|
||||
validate((long) Short.MAX_VALUE, decoder.readObject());
|
||||
validate((long) Short.MIN_VALUE, decoder.readObject());
|
||||
validate((long) Integer.MAX_VALUE, decoder.readObject());
|
||||
validate((long) Integer.MIN_VALUE, decoder.readObject());
|
||||
validate(Long.MAX_VALUE, decoder.readObject());
|
||||
validate(Long.MIN_VALUE, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(long value, Object object) {
|
||||
if (!object.equals(Long.valueOf(value))) {
|
||||
throw new Error("long " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
179
test/jdk/java/beans/XMLDecoder/spec/TestMethod.java
Normal file
179
test/jdk/java/beans/XMLDecoder/spec/TestMethod.java
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <method> element
|
||||
* @run main/othervm TestMethod
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestMethod extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <new class=\"TestMethod$A\">\n"
|
||||
+ " <method name=\"m\">\n"
|
||||
+ " <new class=\"TestMethod$Y\"/>\n"
|
||||
+ " <new class=\"TestMethod$Y\"/>\n"
|
||||
+ " </method>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestMethod$B\">\n"
|
||||
+ " <method name=\"m\">\n"
|
||||
+ " <new class=\"TestMethod$Y\"/>\n"
|
||||
+ " <new class=\"TestMethod$Y\"/>\n"
|
||||
+ " </method>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestMethod$C\">\n"
|
||||
+ " <method name=\"m\">\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " </method>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestMethod$D\">\n"
|
||||
+ " <method name=\"m\">\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " </method>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestMethod$E\">\n"
|
||||
+ " <method name=\"m\">\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " <new class=\"TestMethod$Z\"/>\n"
|
||||
+ " </method>\n"
|
||||
+ " </new>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestMethod().test();
|
||||
}
|
||||
|
||||
private NoSuchMethodException exception;
|
||||
|
||||
@Override
|
||||
public void exceptionThrown(Exception exception) {
|
||||
if (this.exception != null) {
|
||||
// only one exception allowed
|
||||
super.exceptionThrown(exception);
|
||||
} else if (exception instanceof NoSuchMethodException) {
|
||||
// expected exception: ambiguous methods are found
|
||||
this.exception = (NoSuchMethodException) exception;
|
||||
} else {
|
||||
super.exceptionThrown(exception);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
this.exception = null;
|
||||
validate(decoder, A.class);
|
||||
validate(decoder, B.class);
|
||||
validate(decoder, C.class);
|
||||
validate(decoder, D.class);
|
||||
validate(decoder, E.class);
|
||||
if (this.exception == null) {
|
||||
throw new Error("NoSuchMethodException expected");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validate(XMLDecoder decoder, Class type) {
|
||||
if (!type.equals(decoder.readObject().getClass())) {
|
||||
throw new Error("unexpected class");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All ambiguous method declarations should fail.
|
||||
*/
|
||||
public static class A {
|
||||
public void m(X x1, X x2) {
|
||||
throw new Error("A.m(X,X) should not be called");
|
||||
}
|
||||
|
||||
public void m(X x1, Y y2) {
|
||||
throw new Error("A.m(X,Y) should not be called");
|
||||
}
|
||||
|
||||
public void m(Y y1, X x2) {
|
||||
throw new Error("A.m(Y,X) should not be called");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The most specific method in this case would be the second declaration.
|
||||
*/
|
||||
public static class B {
|
||||
public void m(X x1, X x2) {
|
||||
throw new Error("B.m(X,X) should not be called");
|
||||
}
|
||||
|
||||
public void m(X x1, Y y2) {
|
||||
// expected: B.m(X,Y) should be called
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The most specific method in this case would be the first declaration.
|
||||
*/
|
||||
public static class C {
|
||||
public void m(Y y1, Y y2) {
|
||||
// expected: C.m(Y,Y) should be called
|
||||
}
|
||||
|
||||
public void m(X x1, X x2) {
|
||||
throw new Error("C.m(X,X) should not be called");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as the previous case but flip methods.
|
||||
*/
|
||||
public static class D {
|
||||
public void m(X x1, X x2) {
|
||||
throw new Error("D.m(X,X) should not be called");
|
||||
}
|
||||
|
||||
public void m(Y y1, Y y2) {
|
||||
// expected: D.m(Y,Y) should be called
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method should be called with (Z,Z).
|
||||
*/
|
||||
public static class E {
|
||||
public void m(X x1, X x2) {
|
||||
// expected: E.m(X,X) should be called
|
||||
}
|
||||
}
|
||||
|
||||
public static class X {
|
||||
}
|
||||
|
||||
public static class Y extends X {
|
||||
}
|
||||
|
||||
public static class Z extends Y {
|
||||
}
|
||||
}
|
||||
91
test/jdk/java/beans/XMLDecoder/spec/TestNew.java
Normal file
91
test/jdk/java/beans/XMLDecoder/spec/TestNew.java
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <new> element
|
||||
* @run main/othervm TestNew
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class TestNew extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <new class=\"TestNew\"/>\n"
|
||||
+ " <new class=\"TestNew\">\n"
|
||||
+ " <null/>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestNew\">\n"
|
||||
+ " <string>single</string>\n"
|
||||
+ " </new>\n"
|
||||
+ " <new class=\"TestNew\">\n"
|
||||
+ " <string>first</string>\n"
|
||||
+ " <string>second</string>\n"
|
||||
+ " <string>third</string>\n"
|
||||
+ " </new>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestNew().test();
|
||||
}
|
||||
|
||||
private List<String> list;
|
||||
|
||||
public TestNew(String...messages) {
|
||||
if (messages != null) {
|
||||
this.list = new ArrayList<String>();
|
||||
for (String message : messages) {
|
||||
this.list.add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof TestNew) {
|
||||
TestNew test = (TestNew) object;
|
||||
return (test.list == null)
|
||||
? this.list == null
|
||||
: test.list.equals(this.list);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(decoder.readObject());
|
||||
validate(decoder.readObject(), null);
|
||||
validate(decoder.readObject(), "single");
|
||||
validate(decoder.readObject(), "first", "second", "third");
|
||||
}
|
||||
|
||||
private static void validate(Object object, String...messages) {
|
||||
if (!object.equals(new TestNew(messages))) {
|
||||
throw new Error("expected object");
|
||||
}
|
||||
}
|
||||
}
|
||||
49
test/jdk/java/beans/XMLDecoder/spec/TestNull.java
Normal file
49
test/jdk/java/beans/XMLDecoder/spec/TestNull.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <null> element
|
||||
* @run main/othervm TestNull
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestNull extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <null/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestNull().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
if (null != decoder.readObject()) {
|
||||
throw new Error("null value expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
85
test/jdk/java/beans/XMLDecoder/spec/TestObject.java
Normal file
85
test/jdk/java/beans/XMLDecoder/spec/TestObject.java
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <object> element
|
||||
* @run main/othervm TestObject
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
public final class TestObject extends AbstractTest {
|
||||
public static final String XML // TODO
|
||||
= "<java>\n"
|
||||
+ " <object class=\"javax.swing.JPanel\">\n"
|
||||
+ " <void method=\"add\">\n"
|
||||
+ " <object id=\"button\" class=\"javax.swing.JButton\">\n"
|
||||
+ " <string>button</string>\n"
|
||||
+ " <void property=\"verticalAlignment\">\n"
|
||||
+ " <object field=\"CENTER\" class=\"javax.swing.SwingConstants\"/>\n"
|
||||
+ " </void>\n"
|
||||
+ " </object>\n"
|
||||
+ " </void>\n"
|
||||
+ " <void method=\"add\">\n"
|
||||
+ " <object class=\"javax.swing.JLabel\">\n"
|
||||
+ " <string>label</string>\n"
|
||||
+ " <void property=\"labelFor\">\n"
|
||||
+ " <object idref=\"button\"/>\n"
|
||||
+ " </void>\n"
|
||||
+ " </object>\n"
|
||||
+ " </void>\n"
|
||||
+ " </object>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestObject().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
JPanel panel = (JPanel) decoder.readObject();
|
||||
if (2 != panel.getComponents().length) {
|
||||
throw new Error("unexpected component count");
|
||||
}
|
||||
JButton button = (JButton) panel.getComponents()[0];
|
||||
if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
|
||||
throw new Error("unexpected button text");
|
||||
}
|
||||
if (SwingConstants.CENTER != button.getVerticalAlignment()) {
|
||||
throw new Error("unexpected vertical alignment");
|
||||
}
|
||||
JLabel label = (JLabel) panel.getComponents()[1];
|
||||
if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
|
||||
throw new Error("unexpected label text");
|
||||
}
|
||||
if (button != label.getLabelFor()) {
|
||||
throw new Error("unexpected component");
|
||||
}
|
||||
}
|
||||
}
|
||||
89
test/jdk/java/beans/XMLDecoder/spec/TestProperty.java
Normal file
89
test/jdk/java/beans/XMLDecoder/spec/TestProperty.java
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <property> element
|
||||
* @run main/othervm TestProperty
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestProperty extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <property name=\"owner\">\n"
|
||||
+ " <property name=\"message\">\n"
|
||||
+ " <string>message</string>\n"
|
||||
+ " </property>\n"
|
||||
+ " <property id=\"message\" name=\"message\"/>\n"
|
||||
+ " <property name=\"indexed\" index=\"1\">\n"
|
||||
+ " <string>indexed</string>\n"
|
||||
+ " </property>\n"
|
||||
+ " <property id=\"indexed\" name=\"indexed\" index=\"1\"/>\n"
|
||||
+ " </property>\n"
|
||||
+ " <var idref=\"message\"/>\n"
|
||||
+ " <var idref=\"indexed\"/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestProperty().test();
|
||||
}
|
||||
|
||||
private int index;
|
||||
private String message;
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getIndexed(int index) {
|
||||
if (this.index != index) {
|
||||
throw new Error("unexpected index");
|
||||
}
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setIndexed(int index, String message) {
|
||||
this.index = index;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
decoder.setOwner(this);
|
||||
validate(decoder, "message");
|
||||
validate(decoder, "indexed");
|
||||
}
|
||||
|
||||
private static void validate(XMLDecoder decoder, String name) {
|
||||
if (!decoder.readObject().equals(name)) {
|
||||
throw new Error(name + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
61
test/jdk/java/beans/XMLDecoder/spec/TestShort.java
Normal file
61
test/jdk/java/beans/XMLDecoder/spec/TestShort.java
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <short> element
|
||||
* @run main/othervm TestShort
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestShort extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <short>0</short>\n"
|
||||
+ " <short>127</short>\n"
|
||||
+ " <short>-128</short>\n"
|
||||
+ " <short>32767</short>\n"
|
||||
+ " <short>-32768</short>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestShort().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate((short) 0, decoder.readObject());
|
||||
validate((short) Byte.MAX_VALUE, decoder.readObject());
|
||||
validate((short) Byte.MIN_VALUE, decoder.readObject());
|
||||
validate(Short.MAX_VALUE, decoder.readObject());
|
||||
validate(Short.MIN_VALUE, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(short value, Object object) {
|
||||
if (!object.equals(Short.valueOf(value))) {
|
||||
throw new Error("short " + value + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
61
test/jdk/java/beans/XMLDecoder/spec/TestString.java
Normal file
61
test/jdk/java/beans/XMLDecoder/spec/TestString.java
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <string> element
|
||||
* @run main/othervm TestString
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestString extends AbstractTest {
|
||||
public static final String PREFIX = " prefix ";
|
||||
public static final String POSTFIX = " postfix ";
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <string>" + PREFIX + "</string>\n"
|
||||
+ " <string>" + POSTFIX + "</string>\n"
|
||||
+ " <string>" + PREFIX + POSTFIX + "</string>\n"
|
||||
+ " <string>" + PREFIX + "<char code=\"0\"/>" + POSTFIX + "</string>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestString().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
validate(PREFIX, decoder.readObject());
|
||||
validate(POSTFIX, decoder.readObject());
|
||||
validate(PREFIX + POSTFIX, decoder.readObject());
|
||||
validate(PREFIX + '\u0000' + POSTFIX, decoder.readObject());
|
||||
}
|
||||
|
||||
private static void validate(String name, Object object) {
|
||||
if (!object.equals(name)) {
|
||||
throw new Error(name + " expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
49
test/jdk/java/beans/XMLDecoder/spec/TestTrue.java
Normal file
49
test/jdk/java/beans/XMLDecoder/spec/TestTrue.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <true> element
|
||||
* @run main/othervm TestTrue
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestTrue extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java>\n"
|
||||
+ " <true/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestTrue().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
if (!Boolean.TRUE.equals(decoder.readObject())) {
|
||||
throw new Error("true expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
55
test/jdk/java/beans/XMLDecoder/spec/TestVar.java
Normal file
55
test/jdk/java/beans/XMLDecoder/spec/TestVar.java
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests <var> element
|
||||
* @run main/othervm TestVar
|
||||
* @author Sergey Malenkov
|
||||
*/
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
public final class TestVar extends AbstractTest {
|
||||
public static final String XML
|
||||
= "<java id=\"decoder\">\n"
|
||||
+ " <var idref=\"decoder\"/>\n"
|
||||
+ " <var id=\"another\" idref=\"decoder\"/>\n"
|
||||
+ " <var idref=\"another\"/>\n"
|
||||
+ " <var id=\"decoder\" idref=\"another\"/>\n"
|
||||
+ " <var idref=\"decoder\"/>\n"
|
||||
+ "</java>";
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestVar().test();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(XMLDecoder decoder) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (decoder != decoder.readObject()) {
|
||||
throw new Error("decoder instance expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue