Skip to content

Commit fdf638a

Browse files
committed
SWS-1036 - Make SimpleXsdSchema's toString more resilient
1 parent 8c654a3 commit fdf638a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

spring-xml/src/main/java/org/springframework/xml/xsd/SimpleXsdSchema.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
*
4444
* @author Mark LaFond
4545
* @author Arjen Poutsma
46+
* @author Greg Turnquist
4647
* @since 1.5.0
4748
*/
4849
public class SimpleXsdSchema implements XsdSchema, InitializingBean {
@@ -91,6 +92,9 @@ public void setXsd(Resource xsdResource) {
9192

9293
@Override
9394
public String getTargetNamespace() {
95+
96+
Assert.notNull(schemaElement, "schemaElement must not be null! Did you run afterPropertiesSet() or register this as a Spring bean?");
97+
9498
return schemaElement.getAttribute("targetNamespace");
9599
}
96100

spring-xml/src/test/java/org/springframework/xml/xsd/SimpleXsdSchemaTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.xml.xsd;
1818

19+
import org.junit.Test;
20+
1921
import org.springframework.core.io.Resource;
2022

2123
public class SimpleXsdSchemaTest extends AbstractXsdSchemaTestCase {
@@ -27,4 +29,11 @@ protected XsdSchema createSchema(Resource resource) throws Exception {
2729
return schema;
2830
}
2931

32+
@Test(expected = IllegalArgumentException.class)
33+
public void testBareXsdSchema() {
34+
35+
SimpleXsdSchema schema = new SimpleXsdSchema();
36+
schema.toString();
37+
}
38+
3039
}

0 commit comments

Comments
 (0)