Error unmarshalling xml in java-8 “secure-processing org.xml.sax.SAXNotRecognizedException causing java.lang.IllegalStateException”

后端 未结 11 465
时光取名叫无心
时光取名叫无心 2020-12-05 00:21

The following code worked fine in Java 7

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

String          


        
11条回答
  •  情深已故
    2020-12-05 01:14

    It was a dependency problem.

    Here is my way how I solved the problem:

    1. Make a new maven project, with that simple pieces of code, I attached below, the programm crashed normally with an error, that the structure couldn't be parsed which is ok.
    2. Copy your dependencies into the project pom.xml, now the programm should crash (as described above)

    3. no you remove dependencies after your favoured method (good guessing, Bisection , 1-by-1 ..) to find the "bad" dependency. Maybe someone has a better (more professional) method, this one worked for me.

    now you can descide what to do, maybe a new version is available, in our case it was out own package of a colleage, where he included a package of a colleage, which i could exclude.

    public class Test {
        public Test() {
        }
        public static void main(String[] args) {
            try {
                StringReader reader = new StringReader("");
                JAXBContext jc = JAXBContext.newInstance(TestXML.class);
                Unmarshaller unmarshaller = jc.createUnmarshaller();
                TestXML testXMLs = (TestXML) unmarshaller.unmarshal(reader);
            } catch (JAXBException e) {
                e.printStackTrace();
            }
        }
    }
    

    and the testXML class

    @XmlRootElement(name="rss")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class TestXML {   
        public TestXML() {
        }
    
        @XmlElementWrapper(name="channel")
        @XmlElement(name="item")
        private int i ;
    
        public int getI() {
            return i;
        }    
        public void setI(int i) {
            this.i = i;
        }
    }
    

    BTW: In my case it was

    
        jcs
        jcs
        1.3
    
    

    Hope that helps.

提交回复
热议问题