Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/bind/jxc/8073872/SchemagenStackOverflow.java
38862 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 807387226* @summary test that stackoverflow is not observable when element27* references containing class28* @compile Foo.java29* @run testng/othervm SchemagenStackOverflow30*/3132import java.io.IOException;33import java.nio.file.Files;34import java.nio.file.Path;35import java.nio.file.Paths;36import java.util.stream.Collectors;37import javax.xml.bind.JAXBContext;38import javax.xml.bind.SchemaOutputResolver;39import javax.xml.transform.Result;40import javax.xml.transform.stream.StreamResult;41import org.testng.Assert;42import org.testng.annotations.Test;4344public class SchemagenStackOverflow {4546@Test47public void schemagenStackOverflowTest() throws Exception {48// Create new instance of JAXB context49JAXBContext context = JAXBContext.newInstance(Foo.class);50context.generateSchema(new TestOutputResolver());5152// Read schema content from file53String content = Files.lines(resultSchemaFile).collect(Collectors.joining(""));54System.out.println("Generated schema content:" + content);5556// Check if schema was generated: check class and list object names57Assert.assertTrue(content.contains("name=\"Foo\""));58Assert.assertTrue(content.contains("name=\"fooObject\""));59}6061// Schemagen output resolver62class TestOutputResolver extends SchemaOutputResolver {63@Override64public Result createOutput(String namespaceUri, String fileName)65throws IOException {66return new StreamResult(resultSchemaFile.toFile());67}68}6970// Schemagen output file name and path71static final String SCHEMA_FILENAME = "generatedSchema.xsd";72Path resultSchemaFile = Paths.get(System.getProperty("user.dir", "."))73.resolve(SCHEMA_FILENAME);7475}767778