Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 359095 - get NullPointerException when output xml schema
Summary: get NullPointerException when output xml schema
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Matt MacIvor CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-27 11:25 EDT by Missing name CLA
Modified: 2022-06-09 10:04 EDT (History)
2 users (show)

See Also:


Attachments
proposed fix and test (22.64 KB, patch)
2011-10-05 10:43 EDT, Matt MacIvor CLA
no flags Details | Diff
updated fix and test (21.91 KB, patch)
2011-10-05 13:18 EDT, Matt MacIvor CLA
no flags Details | Diff
updated patch (23.46 KB, patch)
2011-10-05 15:30 EDT, Matt MacIvor CLA
no flags Details | Diff
Updated Patch (23.55 KB, patch)
2011-10-05 16:31 EDT, Matt MacIvor CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Missing name CLA 2011-09-27 11:25:14 EDT
Build Identifier: Implementation-Version: 2.3.0.v20110604-r9504

(1) first create a simple java bean:
  @XmlRootElement(name="my-world2")
public class MyWorld2 {
	private String name;
	private String email;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	

	private Boolean emailConfirmed;
	@XmlPath("email/@confirmed")
	public Boolean isEmailConfirmed() {
		return emailConfirmed;
	}
	public void setEmailConfirmed(Boolean emailConfirmed) {
		this.emailConfirmed = emailConfirmed;
	}
	
	private String homePhone;
	@XmlPath("phones/phone[@type='home']/text()")
	public String getHomePhone() {
		return homePhone;
	}
	public void setHomePhone(String homePhone) {
		this.homePhone = homePhone;
	}
	
	private String workPhone;
	@XmlPath("phones/phone[@type='work']/text()")
	public String getWorkPhone() {
		return workPhone;
	}
	public void setWorkPhone(String workPhone) {
		this.workPhone = workPhone;
	}

(2) write test code :
	@Test
	public void testOutputSchema() throws Exception {	
	    final SchemaOutputResolver sor = new SchemaOutputResolver() {
	        @Override
	        public Result createOutput(String namespaceUri,
	                String suggestedFileName) throws IOException {
	            return new StreamResult(System.out);
	        }
	    };

	    JAXBContext jc = JAXBContext.newInstance(MyWorld2.class);
	    jc.generateSchema(sor);

	}
(3) run test code and get this exception:
java.lang.NullPointerException
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.buildSchemaComponentsForXPath(SchemaGenerator.java:1116)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.addXPathToSchema(SchemaGenerator.java:1391)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.addToSchemaType(SchemaGenerator.java:438)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.populateSchemaTypes(SchemaGenerator.java:547)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.generateSchema(SchemaGenerator.java:144)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.generateSchema(SchemaGenerator.java:130)
	at org.eclipse.persistence.jaxb.compiler.Generator.generateSchemaFiles(Generator.java:211)
	at org.eclipse.persistence.jaxb.JAXBContext.generateSchema(JAXBContext.java:235)
	at org.eclipse.persistence.jaxb.JAXBContext.generateSchema(JAXBContext.java:208)
	at com.tungle.rest.model.MyWorld2Test.testOutputSchema(MyWorld2Test.java:25)

Reproducible: Always

Steps to Reproduce:
1. first create a simple java bean:
  @XmlRootElement(name="my-world2")
public class MyWorld2 {
	private String name;
	private String email;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	

	private Boolean emailConfirmed;
	@XmlPath("email/@confirmed")
	public Boolean isEmailConfirmed() {
		return emailConfirmed;
	}
	public void setEmailConfirmed(Boolean emailConfirmed) {
		this.emailConfirmed = emailConfirmed;
	}
	
	private String homePhone;
	@XmlPath("phones/phone[@type='home']/text()")
	public String getHomePhone() {
		return homePhone;
	}
	public void setHomePhone(String homePhone) {
		this.homePhone = homePhone;
	}
	
	private String workPhone;
	@XmlPath("phones/phone[@type='work']/text()")
	public String getWorkPhone() {
		return workPhone;
	}
	public void setWorkPhone(String workPhone) {
		this.workPhone = workPhone;
	}

2. write test code :
	@Test
	public void testOutputSchema() throws Exception {	
	    final SchemaOutputResolver sor = new SchemaOutputResolver() {
	        @Override
	        public Result createOutput(String namespaceUri,
	                String suggestedFileName) throws IOException {
	            return new StreamResult(System.out);
	        }
	    };

	    JAXBContext jc = JAXBContext.newInstance(MyWorld2.class);
	    jc.generateSchema(sor);

	}

3. run test code and get this exception:
java.lang.NullPointerException
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.buildSchemaComponentsForXPath(SchemaGenerator.java:1116)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.addXPathToSchema(SchemaGenerator.java:1391)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.addToSchemaType(SchemaGenerator.java:438)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.populateSchemaTypes(SchemaGenerator.java:547)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.generateSchema(SchemaGenerator.java:144)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.generateSchema(SchemaGenerator.java:130)
	at org.eclipse.persistence.jaxb.compiler.Generator.generateSchemaFiles(Generator.java:211)
	at org.eclipse.persistence.jaxb.JAXBContext.generateSchema(JAXBContext.java:235)
	at org.eclipse.persistence.jaxb.JAXBContext.generateSchema(JAXBContext.java:208)
	at com.tungle.rest.model.MyWorld2Test.testOutputSchema(MyWorld2Test.java:25)

4. if I comment the property "emailConfirmed", then the unit test can output correct schema.
Comment 1 Matt MacIvor CLA 2011-10-05 10:43:19 EDT
Created attachment 204601 [details]
proposed fix and test
Comment 2 Matt MacIvor CLA 2011-10-05 10:46:05 EDT
The issue causing the null pointer has to do with the @XmlPath("email/@confirmed") where the attribute is being added to the email element, which already exists, but as a simple type. 

After fixing this, it was revealed that schema generation for predicates in XmlPath wasn't working correctly. This patch addresses the issue with predicates as well as the original NullPointerException.
Comment 3 Matt MacIvor CLA 2011-10-05 13:18:57 EDT
Created attachment 204614 [details]
updated fix and test

Updated patch, supports XmlPaths with multiple predicates.
Comment 4 Matt MacIvor CLA 2011-10-05 15:30:27 EDT
Created attachment 204626 [details]
updated patch
Comment 5 Matt MacIvor CLA 2011-10-05 16:31:52 EDT
Created attachment 204635 [details]
Updated Patch
Comment 6 Matt MacIvor CLA 2011-10-06 09:58:45 EDT
Final patch has been submitted to SVN
Will appear in 2.4 nightly builds.
Comment 7 Missing name CLA 2012-01-09 13:14:12 EST
(In reply to comment #6)
> Final patch has been submitted to SVN
> Will appear in 2.4 nightly builds.

Tested on eclipselink-2.4.0.v20111229-r10621.zip
still get NullPointerException on the same code:

java.lang.NullPointerException
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.getSchemaForNamespace(SchemaGenerator.java:660)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.getPrefixForNamespace(SchemaGenerator.java:701)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.buildAttribute(SchemaGenerator.java:1581)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.addToSchemaType(SchemaGenerator.java:478)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.populateSchemaTypes(SchemaGenerator.java:560)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.generateSchema(SchemaGenerator.java:145)
	at org.eclipse.persistence.jaxb.compiler.SchemaGenerator.generateSchema(SchemaGenerator.java:131)
	at org.eclipse.persistence.jaxb.compiler.Generator.generateSchemaFiles(Generator.java:220)
	at org.eclipse.persistence.jaxb.JAXBContext.generateSchema(JAXBContext.java:325)
	at org.eclipse.persistence.jaxb.JAXBContext.generateSchema(JAXBContext.java:290)
	at com.tungle.rest.model.MyWorldTest.testOutputSchema(MyWorldTest.java:80)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
	at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
	at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
	at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
	at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Comment 8 Matt MacIvor CLA 2012-02-09 14:53:48 EST
Have attempted running the provided test code against the latest EclipseLink 2.4, and don't see the NullPointerException. I get the following schema generated for MyWorld2.class:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <xsd:complexType name="myWorld2">
      <xsd:sequence>
         <xsd:element name="email" minOccurs="0">
            <xsd:complexType>
               <xsd:simpleContent>
                  <xsd:extension base="xsd:string">
                     <xsd:attribute name="confirmed" type="xsd:boolean"/>
                  </xsd:extension>
               </xsd:simpleContent>
            </xsd:complexType>
         </xsd:element>
         <xsd:element name="phones" minOccurs="0">
            <xsd:complexType>
               <xsd:sequence>
                  <xsd:element name="phone" minOccurs="0" maxOccurs="unbounded">
                     <xsd:complexType>
                        <xsd:simpleContent>
                           <xsd:extension base="xsd:string">
                              <xsd:attribute name="type" type="xsd:string"/>
                           </xsd:extension>
                        </xsd:simpleContent>
                     </xsd:complexType>
                  </xsd:element>
               </xsd:sequence>
            </xsd:complexType>
         </xsd:element>
         <xsd:element name="name" type="xsd:string" minOccurs="0"/>
      </xsd:sequence>
   </xsd:complexType>
</xsd:schema>

Is there anything different between the test case provided above and the test case that is causing the NullPointerException? Is there a package-info.java for MyBean2's package?
Comment 9 Matt MacIvor CLA 2012-05-16 12:35:17 EDT
Still unable to reproduce after the original fix. Unable to contact filer for more details. Marking as closed. Please re-open and provide more details to reproduce if the problem is still appearing the the latest builds.
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:04:25 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink