Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAXBContext.newInstance(Class<?>) throws "JAXBException: Package java.lang with JAXB class xxx defined in a module java.base must be open to at least java.xml.bind module" if the class is in java.lang package #1184

Closed
Tomas-Kraus opened this issue Apr 20, 2018 · 3 comments

Comments

@Tomas-Kraus
Copy link
Member

Previously tracked via: https://bugs.openjdk.java.net/browse/JDK-8184726

Run the following java program:

import java.io.StringReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
import javax.xml.transform.stream.StreamSource;

public class TestJAXB {

public static void main(String[] args) throws Exception { 
    // marshal 
    int[] x = new int[]{1,5,2,3,4}; 
    JAXBElement<int[]> xe = new JAXBElement<int[]>(new QName("", "root"), int[].class, JAXBElement.GlobalScope.class, x); 
    Marshaller m = JAXBContext.newInstance(int[].class).createMarshaller(); 
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true); 
    m.marshal(xe,System.out); 
     
    // unmarshal 
    Unmarshaller u = JAXBContext.newInstance(int[].class).createUnmarshaller(); 
    JAXBElement e = u.unmarshal(new StreamSource(new StringReader( 
            "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + 
            "<root>\n" + 
            " <item>1</item>\n" + 
            " <item>5</item>\n" + 
            " <item>2</item>\n" + 
            " <item>3</item>\n" + 
            " <item>4</item>\n" + 
            "</root>\n")), int[].class); 
} 

}

Exception in thread "main" javax.xml.bind.JAXBException: Package java.lang with JAXB class [I defined in a module java.base must be open to at least java.xml.bind module.
at java.xml.bind@9/javax.xml.bind.ModuleUtil.delegateAddOpensToImplModule(ModuleUtil.java:148)
at java.xml.bind@9/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:285)
at java.xml.bind@9/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:270)
at java.xml.bind@9/javax.xml.bind.ContextFinder.find(ContextFinder.java:407)
at java.xml.bind@9/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:706)
at java.xml.bind@9/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:647)
at TestJAXB.main(TestJAXB.java:16)

Please note, the exception is thrown in JAXBContext.newInstance(int[].class), other code is just to show a whole example.

@Tomas-Kraus
Copy link
Member Author

@lukaseder Commented
I'm also running into this when unit testing https://github.com/jOOQ/jOOX. Adding

    opens org.joox to java.xml.bind;

To the module-info.java seems to work, but this shouldn't be required IMO.

@bravehorsie
Copy link
Contributor

Should be fixed in 2.3.1, can you retest please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants