Tue, 29 Mar 2016 13:16:00 +0300
8073872: Schemagen fails with StackOverflowError if element references containing class
Reviewed-by: lancea
src/share/jaxws_classes/com/sun/xml/internal/bind/v2/schemagen/XmlSchemaGenerator.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/schemagen/XmlSchemaGenerator.java Thu Mar 24 01:15:32 2016 +0300 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/schemagen/XmlSchemaGenerator.java Tue Mar 29 13:16:00 2016 +0300 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -110,6 +110,7 @@ 1.11 import com.sun.xml.internal.txw2.output.ResultFactory; 1.12 import com.sun.xml.internal.txw2.output.XmlSerializer; 1.13 import java.util.Collection; 1.14 +import java.util.HashSet; 1.15 import org.xml.sax.SAXParseException; 1.16 1.17 /** 1.18 @@ -436,7 +437,7 @@ 1.19 1.20 if(logger.isLoggable(Level.FINE)) { 1.21 // debug logging to see what's going on. 1.22 - logger.log(Level.FINE,"Wrigin XML Schema for "+toString(),new StackRecorder()); 1.23 + logger.log(Level.FINE,"Writing XML Schema for "+toString(),new StackRecorder()); 1.24 } 1.25 1.26 // make it fool-proof 1.27 @@ -465,6 +466,8 @@ 1.28 systemIds.put(n,output.getSystemId()); 1.29 } 1.30 } 1.31 + //Clear the namespace specific set with already written classes 1.32 + n.resetWritten(); 1.33 } 1.34 1.35 // then write'em all 1.36 @@ -542,6 +545,11 @@ 1.37 */ 1.38 private boolean useMimeNs; 1.39 1.40 + /** 1.41 + * Container for already processed classes 1.42 + */ 1.43 + private final Set<ClassInfo> written = new HashSet<ClassInfo>(); 1.44 + 1.45 public Namespace(String uri) { 1.46 this.uri = uri; 1.47 assert !XmlSchemaGenerator.this.namespaces.containsKey(uri); 1.48 @@ -549,6 +557,13 @@ 1.49 } 1.50 1.51 /** 1.52 + * Clear out the set of already processed classes for this namespace 1.53 + */ 1.54 + void resetWritten() { 1.55 + written.clear(); 1.56 + } 1.57 + 1.58 + /** 1.59 * Process the given PropertyInfo looking for references to namespaces that 1.60 * are foreign to the given namespace. Any foreign namespace references 1.61 * found are added to the given namespaces dependency list and an <import> 1.62 @@ -853,6 +868,10 @@ 1.63 * @param parent the writer of the parent element into which the type will be defined 1.64 */ 1.65 private void writeClass(ClassInfo<T,C> c, TypeHost parent) { 1.66 + if (written.contains(c)) { // to avoid cycles let's check if we haven't already processed the class 1.67 + return; 1.68 + } 1.69 + written.add(c); 1.70 // special handling for value properties 1.71 if (containsValueProp(c)) { 1.72 if (c.getProperties().size() == 1) {