From b.buchner at isys-software.de Thu Aug 9 07:08:48 2012 From: b.buchner at isys-software.de (=?ISO-8859-15?Q?Bj=F6rn_Buchner?=) Date: Thu, 09 Aug 2012 16:08:48 +0200 Subject: [jdom-interest] Serialization Trouble through Inheritance Message-ID: <5023C470.3090500@isys-software.de> Hi Folks, I am using the JDOM 2.0.2 release and experienced some trouble when it comes to serialization. De-/serializing an Element object through the standard ObjectOutput/InputStream is no problem. Trouble starts when I try to deserialize an object of a class that inherits from Element. It always ends with a InvalidClassException: no valid constructor. Normally this indicates that JRE is missing a public default constructor, but as you can see in the example below the subclass has a default constructor. Thanks in advance for your help Example code: public class MyElement extends Element { private static final long serialVersionUID = -4220756491425652053L; public MyElement() { super(); } public static void main(String ... args) throws IOException, ClassNotFoundException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutputStream outStream = new ObjectOutputStream(buffer); MyElement element = new MyElement(); outStream.writeObject(element); outStream.flush(); ObjectInputStream inStream = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); element = (MyElement)inStream.readObject(); } } Result: Exception in thread "main" java.io.InvalidClassException: ; no valid constructor at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147) at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) at .main(MyElement.java:29) -- iSYS Software GmbH Bj?rn Buchner Tel: +49 (0) 89 46 23 28-0 | Fax (0) 89 46 23 28-14 email: b.buchner at isys-software.de Grillparzerstr. 10 | D-81675 Muenchen www.isys-software.de Sitz der Gesellschaft: M?nchen | HRB 111760 Geschaeftsfuehrer: Prof. Dr. Peter Mandl und Michael Sailer From jdom at tuis.net Thu Aug 9 07:37:24 2012 From: jdom at tuis.net (Rolf Lear) Date: Thu, 09 Aug 2012 10:37:24 -0400 Subject: [jdom-interest] Serialization Trouble through Inheritance In-Reply-To: <5023C470.3090500@isys-software.de> References: <5023C470.3090500@isys-software.de> Message-ID: <7030e933e0c98345ce9dd4d059b98581@tuis.net> Hi Bj?rn I don't have my 'JDOM Laptop' with me at the moment, so I can't easily reproduce your problem, but, I suspect this is just an issue of implementing your own read/write object methods. What happens if you add the following methods to your 'MyElement' class? I believe this should fix things..... try it... :-) /** * Serialize out the MyElement. * * @serialData * The Stream protocol is: *
    *
  1. Write the super Element class out... *
* * @param out where to write the Element to. * @throws IOException if there is a writing problem. */ private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); } /** * Read a MyElement off the ObjectInputStream. * * @see #writeObject(ObjectOutputStream) * @param in where to read the Element from. * @throws IOException if there is a reading problem. * @throws ClassNotFoundException when a class cannot be found */ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); } Rolf On Thu, 09 Aug 2012 16:08:48 +0200, Bj?rn Buchner wrote: > Hi Folks, > > I am using the JDOM 2.0.2 release and experienced some trouble when it > comes to serialization. > > De-/serializing an Element object through the standard > ObjectOutput/InputStream is no problem. Trouble starts when I try to > deserialize an object of a class that inherits from Element. > > It always ends with a InvalidClassException: no valid constructor. > Normally this indicates that JRE is missing a public default > constructor, but as you can see in the example below the subclass > has a default constructor. > > Thanks in advance for your help > > Example code: > > public class MyElement extends Element { > > private static final long serialVersionUID = -4220756491425652053L; > > public MyElement() { > super(); > } > > > public static void main(String ... args) throws IOException, > ClassNotFoundException { > ByteArrayOutputStream buffer = new ByteArrayOutputStream(); > ObjectOutputStream outStream = new ObjectOutputStream(buffer); > > MyElement element = new MyElement(); > > outStream.writeObject(element); > outStream.flush(); > ObjectInputStream inStream = new ObjectInputStream(new > ByteArrayInputStream(buffer.toByteArray())); > element = (MyElement)inStream.readObject(); > } > } > > Result: > > Exception in thread "main" java.io.InvalidClassException: > ; no valid constructor > at > java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147) > at > java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755) > at > java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751) > at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) > at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) > at .main(MyElement.java:29) From curoli at gmail.com Thu Aug 9 08:03:52 2012 From: curoli at gmail.com (Oliver Ruebenacker) Date: Thu, 9 Aug 2012 11:03:52 -0400 Subject: [jdom-interest] Serialization Trouble through Inheritance In-Reply-To: <7030e933e0c98345ce9dd4d059b98581@tuis.net> References: <5023C470.3090500@isys-software.de> <7030e933e0c98345ce9dd4d059b98581@tuis.net> Message-ID: Hello, Rolf, it shouldn't be necessary to add these methods. Bj?rn, can you check the import statement for Element? Take care Oliver On Thu, Aug 9, 2012 at 10:37 AM, Rolf Lear wrote: > > Hi Bj?rn > > I don't have my 'JDOM Laptop' with me at the moment, so I can't easily > reproduce your problem, but, I suspect this is just an issue of > implementing your own read/write object methods. > > What happens if you add the following methods to your 'MyElement' class? I > believe this should fix things..... try it... :-) > > > > /** > * Serialize out the MyElement. > * > * @serialData > * The Stream protocol is: > *
    > *
  1. Write the super Element class out... > *
> * > * @param out where to write the Element to. > * @throws IOException if there is a writing problem. > */ > private void writeObject(final ObjectOutputStream out) throws IOException > { > out.defaultWriteObject(); > } > > /** > * Read a MyElement off the ObjectInputStream. > * > * @see #writeObject(ObjectOutputStream) > * @param in where to read the Element from. > * @throws IOException if there is a reading problem. > * @throws ClassNotFoundException when a class cannot be found > */ > private void readObject(final ObjectInputStream in) > throws IOException, ClassNotFoundException { > in.defaultReadObject(); > } > > > Rolf > > > > On Thu, 09 Aug 2012 16:08:48 +0200, Bj?rn Buchner > wrote: >> Hi Folks, >> >> I am using the JDOM 2.0.2 release and experienced some trouble when it >> comes to serialization. >> >> De-/serializing an Element object through the standard >> ObjectOutput/InputStream is no problem. Trouble starts when I try to >> deserialize an object of a class that inherits from Element. >> >> It always ends with a InvalidClassException: no valid constructor. >> Normally this indicates that JRE is missing a public default >> constructor, but as you can see in the example below the subclass >> has a default constructor. >> >> Thanks in advance for your help >> >> Example code: >> >> public class MyElement extends Element { >> >> private static final long serialVersionUID = -4220756491425652053L; >> >> public MyElement() { >> super(); >> } >> >> >> public static void main(String ... args) throws IOException, >> ClassNotFoundException { >> ByteArrayOutputStream buffer = new ByteArrayOutputStream(); >> ObjectOutputStream outStream = new ObjectOutputStream(buffer); >> >> MyElement element = new MyElement(); >> >> outStream.writeObject(element); >> outStream.flush(); >> ObjectInputStream inStream = new ObjectInputStream(new >> ByteArrayInputStream(buffer.toByteArray())); >> element = (MyElement)inStream.readObject(); >> } >> } >> >> Result: >> >> Exception in thread "main" java.io.InvalidClassException: >> ; no valid constructor >> at >> > java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147) >> at >> java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755) >> at >> > java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751) >> at > java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) >> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) >> at .main(MyElement.java:29) > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com -- Java Developer (Bioinformatics) at PanGenX (http://www.pangenx.com) President and Founder of Knowomics (http://www.knowomics.com/wiki/Oliver_Ruebenacker) Consultant at Predictive Medicine (http://predmed.com/people/oliverruebenacker.html) SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org) From jdom at tuis.net Thu Aug 9 08:51:38 2012 From: jdom at tuis.net (Rolf Lear) Date: Thu, 09 Aug 2012 11:51:38 -0400 Subject: [jdom-interest] Serialization Trouble through Inheritance In-Reply-To: References: <5023C470.3090500@isys-software.de> <7030e933e0c98345ce9dd4d059b98581@tuis.net> Message-ID: <58fc14ed849f630b26d520d8417cac0a@tuis.net> Hi Bj?rn, Oliver I have identified what the problem is...... this is not actually a Java bug, but it describes what the JDOM bug is... I think.... http://bugs.sun.com/view_bug.do?bug_id=6522514 What this implies is that there is an issue in the permissions of the JDOM element hierarchy. in my understanding, it goes like this.... org.jdom2.Element extends org.jdom2.Content. org.jdom2.Content extends org.jdom2.CloneBase. org.jdom2.CloneBase is a package-private (not public) class, and CloneBase has no declared constructor (it has the default no-arg constructor). Your class 'MyElement' is not in the org.jdom2 package, so, it cannot 'see' the no-arg constructor for (package private) org.jdom2.CloneBase. Thus the MyElement class cannot be de-serialized. I have 'proven' that this is the logic fault by putting the MyElement class in the org.jdom2 package, and then, miraculously, the code works. When I get home I will try it again but instead with a 'protected' no-arg constructor on org.jdom2.CloneBase, and the MyElement class in some other package..... actually, I have just tried it now, and it works..... Thus, there are two work-arounds: - putting your MyElement code in the org.jdom2 package.... - using the attached org.jdom2.CloneBase class which has a protected no-arg constructor. I have created a new issue (#88), and I have attached a working CloneBase class you can add to your project temporarily..... I will push out JDOM 2.0.3 Rolf On Thu, 9 Aug 2012 11:03:52 -0400, Oliver Ruebenacker wrote: > Hello, > > Rolf, it shouldn't be necessary to add these methods. > > Bj?rn, can you check the import statement for Element? > > Take care > Oliver > > On Thu, Aug 9, 2012 at 10:37 AM, Rolf Lear wrote: >> >> Hi Bj?rn >> >> I don't have my 'JDOM Laptop' with me at the moment, so I can't easily >> reproduce your problem, but, I suspect this is just an issue of >> implementing your own read/write object methods. >> >> What happens if you add the following methods to your 'MyElement' class? >> I >> believe this should fix things..... try it... :-) >> >> >> >> /** >> * Serialize out the MyElement. >> * >> * @serialData >> * The Stream protocol is: >> *
    >> *
  1. Write the super Element class out... >> *
>> * >> * @param out where to write the Element to. >> * @throws IOException if there is a writing problem. >> */ >> private void writeObject(final ObjectOutputStream out) throws >> IOException >> { >> out.defaultWriteObject(); >> } >> >> /** >> * Read a MyElement off the ObjectInputStream. >> * >> * @see #writeObject(ObjectOutputStream) >> * @param in where to read the Element from. >> * @throws IOException if there is a reading problem. >> * @throws ClassNotFoundException when a class cannot be found >> */ >> private void readObject(final ObjectInputStream in) >> throws IOException, ClassNotFoundException { >> in.defaultReadObject(); >> } >> >> >> Rolf >> >> >> >> On Thu, 09 Aug 2012 16:08:48 +0200, Bj?rn Buchner >> wrote: >>> Hi Folks, >>> >>> I am using the JDOM 2.0.2 release and experienced some trouble when it >>> comes to serialization. >>> >>> De-/serializing an Element object through the standard >>> ObjectOutput/InputStream is no problem. Trouble starts when I try to >>> deserialize an object of a class that inherits from Element. >>> >>> It always ends with a InvalidClassException: no valid constructor. >>> Normally this indicates that JRE is missing a public default >>> constructor, but as you can see in the example below the subclass >>> has a default constructor. >>> >>> Thanks in advance for your help >>> >>> Example code: >>> >>> public class MyElement extends Element { >>> >>> private static final long serialVersionUID = -4220756491425652053L; >>> >>> public MyElement() { >>> super(); >>> } >>> >>> >>> public static void main(String ... args) throws IOException, >>> ClassNotFoundException { >>> ByteArrayOutputStream buffer = new ByteArrayOutputStream(); >>> ObjectOutputStream outStream = new ObjectOutputStream(buffer); >>> >>> MyElement element = new MyElement(); >>> >>> outStream.writeObject(element); >>> outStream.flush(); >>> ObjectInputStream inStream = new ObjectInputStream(new >>> ByteArrayInputStream(buffer.toByteArray())); >>> element = (MyElement)inStream.readObject(); >>> } >>> } >>> >>> Result: >>> >>> Exception in thread "main" java.io.InvalidClassException: >>> ; no valid constructor >>> at >>> >> java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147) >>> at >>> java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755) >>> at >>> >> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751) >>> at >> java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) >>> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) >>> at .main(MyElement.java:29) >> _______________________________________________ >> To control your jdom-interest membership: >> http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com -------------- next part -------------- /*-- Copyright (C) 2012 Jason Hunter & Brett McLaughlin. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the disclaimer that follows these conditions in the documentation and/or other materials provided with the distribution. 3. The name "JDOM" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact . 4. Products derived from this software may not be called "JDOM", nor may "JDOM" appear in their name, without prior written permission from the JDOM Project Management . In addition, we request (but do not require) that you include in the end-user documentation provided with the redistribution and/or in the software itself an acknowledgement equivalent to the following: "This product includes software developed by the JDOM Project (http://www.jdom.org/)." Alternatively, the acknowledgment may be graphical using the logos available at http://www.jdom.org/images/logos. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the JDOM Project and was originally created by Jason Hunter and Brett McLaughlin . For more information on the JDOM Project, please see . */ package org.jdom2; /** * This simple class just tidies up any cloneable classes. This method deals * with any CloneNotSupported exceptions. THis class is package private only. * * @author Rolf Lear */ class CloneBase implements Cloneable { /** * Return a deep clone of this instance. Even if this instance has a parent, * the returned clone will not. *

* All JDOM core classes are Cloneable, and never throw * CloneNotSupportedException. Additionally all Cloneable JDOM classes * return the correct type of instance from this method and there is no * need to cast the result (co-variant return vaue). *

* Subclasses of this should still call super.clone() in their clone method. */ @Override protected CloneBase clone() { /* * Additionally, when you use the concept of 'co-variant return values' * you create 'bridge' methods. By way of example, because we change the * return type of clone() from Object to CloneBase, Java is forced to * put in a 'bridge' method that has an Object return type, even though * we never actually call it.

This has an impact on the code * coverage tool Cobertura, which reports that there is missed code (and * there is, the bridge method). It reports it as being '0' calls to the * 'class' line (the class line is marked red). By making this CloneBase * code do the first level of co-variant return, it is this class which * is victim of the Cobertura reporting, not the multiple subclasses * (like Attribute, Document, Content, etc.). */ try { return (CloneBase) super.clone(); } catch (CloneNotSupportedException e) { throw new IllegalStateException(String.format( "Unable to clone class %s which should always support it.", this.getClass().getName()), e); } } } From jdom at tuis.net Thu Aug 9 09:23:03 2012 From: jdom at tuis.net (Rolf Lear) Date: Thu, 09 Aug 2012 12:23:03 -0400 Subject: [jdom-interest] Serialization Trouble through Inheritance In-Reply-To: <58fc14ed849f630b26d520d8417cac0a@tuis.net> References: <5023C470.3090500@isys-software.de> <7030e933e0c98345ce9dd4d059b98581@tuis.net> <58fc14ed849f630b26d520d8417cac0a@tuis.net> Message-ID: <8c833a51067fd75cc9724f73e3242d0b@tuis.net> Hmmm... in a moment of daftness, I attached the wrong file (more haste... less speed). here is the working CloneBase file. Rolf On Thu, 09 Aug 2012 11:51:38 -0400, Rolf Lear wrote: > Hi Bj?rn, Oliver > > I have identified what the problem is...... this is not actually a Java > bug, but it describes what the JDOM bug is... I think.... > > http://bugs.sun.com/view_bug.do?bug_id=6522514 > > What this implies is that there is an issue in the permissions of the JDOM > element hierarchy. > > in my understanding, it goes like this.... > > org.jdom2.Element extends org.jdom2.Content. > org.jdom2.Content extends org.jdom2.CloneBase. > org.jdom2.CloneBase is a package-private (not public) class, and CloneBase > has no declared constructor (it has the default no-arg constructor). > > Your class 'MyElement' is not in the org.jdom2 package, so, it cannot > 'see' the no-arg constructor for (package private) org.jdom2.CloneBase. > > Thus the MyElement class cannot be de-serialized. > > I have 'proven' that this is the logic fault by putting the MyElement > class in the org.jdom2 package, and then, miraculously, the code works. > When I get home I will try it again but instead with a 'protected' no-arg > constructor on org.jdom2.CloneBase, and the MyElement class in some other > package..... actually, I have just tried it now, and it works..... > > Thus, there are two work-arounds: > - putting your MyElement code in the org.jdom2 package.... > - using the attached org.jdom2.CloneBase class which has a protected > no-arg constructor. > > > I have created a new issue (#88), and I have attached a working CloneBase > class you can add to your project temporarily..... > > I will push out JDOM 2.0.3 > > Rolf > > > > > On Thu, 9 Aug 2012 11:03:52 -0400, Oliver Ruebenacker > wrote: >> Hello, >> >> Rolf, it shouldn't be necessary to add these methods. >> >> Bj?rn, can you check the import statement for Element? >> >> Take care >> Oliver >> >> On Thu, Aug 9, 2012 at 10:37 AM, Rolf Lear wrote: >>> >>> Hi Bj?rn >>> >>> I don't have my 'JDOM Laptop' with me at the moment, so I can't easily >>> reproduce your problem, but, I suspect this is just an issue of >>> implementing your own read/write object methods. >>> >>> What happens if you add the following methods to your 'MyElement' > class? >>> I >>> believe this should fix things..... try it... :-) >>> >>> >>> >>> /** >>> * Serialize out the MyElement. >>> * >>> * @serialData >>> * The Stream protocol is: >>> *

    >>> *
  1. Write the super Element class out... >>> *
>>> * >>> * @param out where to write the Element to. >>> * @throws IOException if there is a writing problem. >>> */ >>> private void writeObject(final ObjectOutputStream out) throws >>> IOException >>> { >>> out.defaultWriteObject(); >>> } >>> >>> /** >>> * Read a MyElement off the ObjectInputStream. >>> * >>> * @see #writeObject(ObjectOutputStream) >>> * @param in where to read the Element from. >>> * @throws IOException if there is a reading problem. >>> * @throws ClassNotFoundException when a class cannot be found >>> */ >>> private void readObject(final ObjectInputStream in) >>> throws IOException, ClassNotFoundException { >>> in.defaultReadObject(); >>> } >>> >>> >>> Rolf >>> >>> >>> >>> On Thu, 09 Aug 2012 16:08:48 +0200, Bj?rn Buchner >>> wrote: >>>> Hi Folks, >>>> >>>> I am using the JDOM 2.0.2 release and experienced some trouble when it >>>> comes to serialization. >>>> >>>> De-/serializing an Element object through the standard >>>> ObjectOutput/InputStream is no problem. Trouble starts when I try to >>>> deserialize an object of a class that inherits from Element. >>>> >>>> It always ends with a InvalidClassException: no valid constructor. >>>> Normally this indicates that JRE is missing a public default >>>> constructor, but as you can see in the example below the subclass >>>> has a default constructor. >>>> >>>> Thanks in advance for your help >>>> >>>> Example code: >>>> >>>> public class MyElement extends Element { >>>> >>>> private static final long serialVersionUID = > -4220756491425652053L; >>>> >>>> public MyElement() { >>>> super(); >>>> } >>>> >>>> >>>> public static void main(String ... args) throws IOException, >>>> ClassNotFoundException { >>>> ByteArrayOutputStream buffer = new ByteArrayOutputStream(); >>>> ObjectOutputStream outStream = new ObjectOutputStream(buffer); >>>> >>>> MyElement element = new MyElement(); >>>> >>>> outStream.writeObject(element); >>>> outStream.flush(); >>>> ObjectInputStream inStream = new ObjectInputStream(new >>>> ByteArrayInputStream(buffer.toByteArray())); >>>> element = (MyElement)inStream.readObject(); >>>> } >>>> } >>>> >>>> Result: >>>> >>>> Exception in thread "main" java.io.InvalidClassException: >>>> ; no valid constructor >>>> at >>>> >>> > java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147) >>>> at >>>> java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755) >>>> at >>>> >>> > java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751) >>>> at >>> java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) >>>> at > java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) >>>> at .main(MyElement.java:29) >>> _______________________________________________ >>> To control your jdom-interest membership: >>> http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com -------------- next part -------------- /*-- Copyright (C) 2012 Jason Hunter & Brett McLaughlin. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the disclaimer that follows these conditions in the documentation and/or other materials provided with the distribution. 3. The name "JDOM" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact . 4. Products derived from this software may not be called "JDOM", nor may "JDOM" appear in their name, without prior written permission from the JDOM Project Management . In addition, we request (but do not require) that you include in the end-user documentation provided with the redistribution and/or in the software itself an acknowledgement equivalent to the following: "This product includes software developed by the JDOM Project (http://www.jdom.org/)." Alternatively, the acknowledgment may be graphical using the logos available at http://www.jdom.org/images/logos. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the JDOM Project and was originally created by Jason Hunter and Brett McLaughlin . For more information on the JDOM Project, please see . */ package org.jdom2; /** * This simple class just tidies up any cloneable classes. This method deals * with any CloneNotSupported exceptions. THis class is package private only. * * @author Rolf Lear */ class CloneBase implements Cloneable { /** * Make the default no-arg constructor available to all sub-classes, not just subclasses in the * org.jdom2 package. * */ protected CloneBase() { super(); } /** * Return a deep clone of this instance. Even if this instance has a parent, * the returned clone will not. *

* All JDOM core classes are Cloneable, and never throw * CloneNotSupportedException. Additionally all Cloneable JDOM classes * return the correct type of instance from this method and there is no * need to cast the result (co-variant return vaue). *

* Subclasses of this should still call super.clone() in their clone method. */ @Override protected CloneBase clone() { /* * Additionally, when you use the concept of 'co-variant return values' * you create 'bridge' methods. By way of example, because we change the * return type of clone() from Object to CloneBase, Java is forced to * put in a 'bridge' method that has an Object return type, even though * we never actually call it.

This has an impact on the code * coverage tool Cobertura, which reports that there is missed code (and * there is, the bridge method). It reports it as being '0' calls to the * 'class' line (the class line is marked red). By making this CloneBase * code do the first level of co-variant return, it is this class which * is victim of the Cobertura reporting, not the multiple subclasses * (like Attribute, Document, Content, etc.). */ try { return (CloneBase) super.clone(); } catch (CloneNotSupportedException e) { throw new IllegalStateException(String.format( "Unable to clone class %s which should always support it.", this.getClass().getName()), e); } } } From b.buchner at isys-software.de Thu Aug 9 23:15:09 2012 From: b.buchner at isys-software.de (=?UTF-8?B?QmrDtnJuIEJ1Y2huZXI=?=) Date: Fri, 10 Aug 2012 08:15:09 +0200 Subject: [jdom-interest] Serialization Trouble through Inheritance In-Reply-To: <8c833a51067fd75cc9724f73e3242d0b@tuis.net> References: <5023C470.3090500@isys-software.de> <7030e933e0c98345ce9dd4d059b98581@tuis.net> <58fc14ed849f630b26d520d8417cac0a@tuis.net> <8c833a51067fd75cc9724f73e3242d0b@tuis.net> Message-ID: <5024A6ED.4040901@isys-software.de> Am Donnerstag, 9. August 2012 18:23:03 schrieb Rolf Lear: > Hmmm... in a moment of daftness, I attached the wrong file (more haste... > less speed). > > here is the working CloneBase file. > > > > Rolf > > On Thu, 09 Aug 2012 11:51:38 -0400, Rolf Lear wrote: >> Hi Bj?rn, Oliver >> >> I have identified what the problem is...... this is not actually a Java >> bug, but it describes what the JDOM bug is... I think.... >> >> http://bugs.sun.com/view_bug.do?bug_id=6522514 >> >> What this implies is that there is an issue in the permissions of the > JDOM >> element hierarchy. >> >> in my understanding, it goes like this.... >> >> org.jdom2.Element extends org.jdom2.Content. >> org.jdom2.Content extends org.jdom2.CloneBase. >> org.jdom2.CloneBase is a package-private (not public) class, and > CloneBase >> has no declared constructor (it has the default no-arg constructor). >> >> Your class 'MyElement' is not in the org.jdom2 package, so, it cannot >> 'see' the no-arg constructor for (package private) org.jdom2.CloneBase. >> >> Thus the MyElement class cannot be de-serialized. >> >> I have 'proven' that this is the logic fault by putting the MyElement >> class in the org.jdom2 package, and then, miraculously, the code works. >> When I get home I will try it again but instead with a 'protected' > no-arg >> constructor on org.jdom2.CloneBase, and the MyElement class in some > other >> package..... actually, I have just tried it now, and it works..... >> >> Thus, there are two work-arounds: >> - putting your MyElement code in the org.jdom2 package.... >> - using the attached org.jdom2.CloneBase class which has a protected >> no-arg constructor. >> >> >> I have created a new issue (#88), and I have attached a working > CloneBase >> class you can add to your project temporarily..... >> >> I will push out JDOM 2.0.3 >> >> Rolf >> >> >> >> >> On Thu, 9 Aug 2012 11:03:52 -0400, Oliver Ruebenacker >> wrote: >>> Hello, >>> >>> Rolf, it shouldn't be necessary to add these methods. >>> >>> Bj?rn, can you check the import statement for Element? >>> >>> Take care >>> Oliver >>> >>> On Thu, Aug 9, 2012 at 10:37 AM, Rolf Lear wrote: >>>> >>>> Hi Bj?rn >>>> >>>> I don't have my 'JDOM Laptop' with me at the moment, so I can't easily >>>> reproduce your problem, but, I suspect this is just an issue of >>>> implementing your own read/write object methods. >>>> >>>> What happens if you add the following methods to your 'MyElement' >> class? >>>> I >>>> believe this should fix things..... try it... :-) >>>> >>>> >>>> >>>> /** >>>> * Serialize out the MyElement. >>>> * >>>> * @serialData >>>> * The Stream protocol is: >>>> *

    >>>> *
  1. Write the super Element class out... >>>> *
>>>> * >>>> * @param out where to write the Element to. >>>> * @throws IOException if there is a writing problem. >>>> */ >>>> private void writeObject(final ObjectOutputStream out) throws >>>> IOException >>>> { >>>> out.defaultWriteObject(); >>>> } >>>> >>>> /** >>>> * Read a MyElement off the ObjectInputStream. >>>> * >>>> * @see #writeObject(ObjectOutputStream) >>>> * @param in where to read the Element from. >>>> * @throws IOException if there is a reading problem. >>>> * @throws ClassNotFoundException when a class cannot be found >>>> */ >>>> private void readObject(final ObjectInputStream in) >>>> throws IOException, ClassNotFoundException { >>>> in.defaultReadObject(); >>>> } >>>> >>>> >>>> Rolf >>>> >>>> >>>> >>>> On Thu, 09 Aug 2012 16:08:48 +0200, Bj?rn Buchner >>>> wrote: >>>>> Hi Folks, >>>>> >>>>> I am using the JDOM 2.0.2 release and experienced some trouble when > it >>>>> comes to serialization. >>>>> >>>>> De-/serializing an Element object through the standard >>>>> ObjectOutput/InputStream is no problem. Trouble starts when I try to >>>>> deserialize an object of a class that inherits from Element. >>>>> >>>>> It always ends with a InvalidClassException: no valid constructor. >>>>> Normally this indicates that JRE is missing a public default >>>>> constructor, but as you can see in the example below the subclass >>>>> has a default constructor. >>>>> >>>>> Thanks in advance for your help >>>>> >>>>> Example code: >>>>> >>>>> public class MyElement extends Element { >>>>> >>>>> private static final long serialVersionUID = >> -4220756491425652053L; >>>>> >>>>> public MyElement() { >>>>> super(); >>>>> } >>>>> >>>>> >>>>> public static void main(String ... args) throws IOException, >>>>> ClassNotFoundException { >>>>> ByteArrayOutputStream buffer = new ByteArrayOutputStream(); >>>>> ObjectOutputStream outStream = new > ObjectOutputStream(buffer); >>>>> >>>>> MyElement element = new MyElement(); >>>>> >>>>> outStream.writeObject(element); >>>>> outStream.flush(); >>>>> ObjectInputStream inStream = new ObjectInputStream(new >>>>> ByteArrayInputStream(buffer.toByteArray())); >>>>> element = (MyElement)inStream.readObject(); >>>>> } >>>>> } >>>>> >>>>> Result: >>>>> >>>>> Exception in thread "main" java.io.InvalidClassException: >>>>> ; no valid constructor >>>>> at >>>>> >>>> >> > java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147) >>>>> at >>>>> > java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755) >>>>> at >>>>> >>>> >> > java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751) >>>>> at >>>> java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) >>>>> at >> java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) >>>>> at .main(MyElement.java:29) >>>> _______________________________________________ >>>> To control your jdom-interest membership: >>>> > http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com Hi guys, thank you for your quick responses. I will try out the solution with the altered CloneBase class. Kind Regards Bjoern -- iSYS Software GmbH Bj?rn Buchner Tel: +49 (0) 89 46 23 28-0 | Fax (0) 89 46 23 28-14 email: b.buchner at isys-software.de Grillparzerstr. 10 | D-81675 Muenchen www.isys-software.de Sitz der Gesellschaft: M?nchen | HRB 111760 Geschaeftsfuehrer: Prof. Dr. Peter Mandl und Michael Sailer From b.buchner at isys-software.de Fri Aug 10 02:37:32 2012 From: b.buchner at isys-software.de (=?UTF-8?B?QmrDtnJuIEJ1Y2huZXI=?=) Date: Fri, 10 Aug 2012 11:37:32 +0200 Subject: [jdom-interest] Serialization Trouble through Inheritance In-Reply-To: <5024A6ED.4040901@isys-software.de> References: <5023C470.3090500@isys-software.de> <7030e933e0c98345ce9dd4d059b98581@tuis.net> <58fc14ed849f630b26d520d8417cac0a@tuis.net> <8c833a51067fd75cc9724f73e3242d0b@tuis.net> <5024A6ED.4040901@isys-software.de> Message-ID: <5024D65C.8070804@isys-software.de> Am Freitag, 10. August 2012 08:15:09 schrieb Bj?rn Buchner: > Am Donnerstag, 9. August 2012 18:23:03 schrieb Rolf Lear: >> Hmmm... in a moment of daftness, I attached the wrong file (more >> haste... >> less speed). >> >> here is the working CloneBase file. >> >> >> >> Rolf >> >> On Thu, 09 Aug 2012 11:51:38 -0400, Rolf Lear wrote: >>> Hi Bj?rn, Oliver >>> >>> I have identified what the problem is...... this is not actually a Java >>> bug, but it describes what the JDOM bug is... I think.... >>> >>> http://bugs.sun.com/view_bug.do?bug_id=6522514 >>> >>> What this implies is that there is an issue in the permissions of the >> JDOM >>> element hierarchy. >>> >>> in my understanding, it goes like this.... >>> >>> org.jdom2.Element extends org.jdom2.Content. >>> org.jdom2.Content extends org.jdom2.CloneBase. >>> org.jdom2.CloneBase is a package-private (not public) class, and >> CloneBase >>> has no declared constructor (it has the default no-arg constructor). >>> >>> Your class 'MyElement' is not in the org.jdom2 package, so, it cannot >>> 'see' the no-arg constructor for (package private) org.jdom2.CloneBase. >>> >>> Thus the MyElement class cannot be de-serialized. >>> >>> I have 'proven' that this is the logic fault by putting the MyElement >>> class in the org.jdom2 package, and then, miraculously, the code works. >>> When I get home I will try it again but instead with a 'protected' >> no-arg >>> constructor on org.jdom2.CloneBase, and the MyElement class in some >> other >>> package..... actually, I have just tried it now, and it works..... >>> >>> Thus, there are two work-arounds: >>> - putting your MyElement code in the org.jdom2 package.... >>> - using the attached org.jdom2.CloneBase class which has a protected >>> no-arg constructor. >>> >>> >>> I have created a new issue (#88), and I have attached a working >> CloneBase >>> class you can add to your project temporarily..... >>> >>> I will push out JDOM 2.0.3 >>> >>> Rolf >>> >>> >>> >>> >>> On Thu, 9 Aug 2012 11:03:52 -0400, Oliver Ruebenacker >>> >>> wrote: >>>> Hello, >>>> >>>> Rolf, it shouldn't be necessary to add these methods. >>>> >>>> Bj?rn, can you check the import statement for Element? >>>> >>>> Take care >>>> Oliver >>>> >>>> On Thu, Aug 9, 2012 at 10:37 AM, Rolf Lear wrote: >>>>> >>>>> Hi Bj?rn >>>>> >>>>> I don't have my 'JDOM Laptop' with me at the moment, so I can't >>>>> easily >>>>> reproduce your problem, but, I suspect this is just an issue of >>>>> implementing your own read/write object methods. >>>>> >>>>> What happens if you add the following methods to your 'MyElement' >>> class? >>>>> I >>>>> believe this should fix things..... try it... :-) >>>>> >>>>> >>>>> >>>>> /** >>>>> * Serialize out the MyElement. >>>>> * >>>>> * @serialData >>>>> * The Stream protocol is: >>>>> *
    >>>>> *
  1. Write the super Element class out... >>>>> *
>>>>> * >>>>> * @param out where to write the Element to. >>>>> * @throws IOException if there is a writing problem. >>>>> */ >>>>> private void writeObject(final ObjectOutputStream out) >>>>> throws >>>>> IOException >>>>> { >>>>> out.defaultWriteObject(); >>>>> } >>>>> >>>>> /** >>>>> * Read a MyElement off the ObjectInputStream. >>>>> * >>>>> * @see #writeObject(ObjectOutputStream) >>>>> * @param in where to read the Element from. >>>>> * @throws IOException if there is a reading problem. >>>>> * @throws ClassNotFoundException when a class cannot be >>>>> found >>>>> */ >>>>> private void readObject(final ObjectInputStream in) >>>>> throws IOException, ClassNotFoundException { >>>>> in.defaultReadObject(); >>>>> } >>>>> >>>>> >>>>> Rolf >>>>> >>>>> >>>>> >>>>> On Thu, 09 Aug 2012 16:08:48 +0200, Bj?rn Buchner >>>>> wrote: >>>>>> Hi Folks, >>>>>> >>>>>> I am using the JDOM 2.0.2 release and experienced some trouble when >> it >>>>>> comes to serialization. >>>>>> >>>>>> De-/serializing an Element object through the standard >>>>>> ObjectOutput/InputStream is no problem. Trouble starts when I try to >>>>>> deserialize an object of a class that inherits from Element. >>>>>> >>>>>> It always ends with a InvalidClassException: no valid constructor. >>>>>> Normally this indicates that JRE is missing a public default >>>>>> constructor, but as you can see in the example below the subclass >>>>>> has a default constructor. >>>>>> >>>>>> Thanks in advance for your help >>>>>> >>>>>> Example code: >>>>>> >>>>>> public class MyElement extends Element { >>>>>> >>>>>> private static final long serialVersionUID = >>> -4220756491425652053L; >>>>>> >>>>>> public MyElement() { >>>>>> super(); >>>>>> } >>>>>> >>>>>> >>>>>> public static void main(String ... args) throws IOException, >>>>>> ClassNotFoundException { >>>>>> ByteArrayOutputStream buffer = new ByteArrayOutputStream(); >>>>>> ObjectOutputStream outStream = new >> ObjectOutputStream(buffer); >>>>>> >>>>>> MyElement element = new MyElement(); >>>>>> >>>>>> outStream.writeObject(element); >>>>>> outStream.flush(); >>>>>> ObjectInputStream inStream = new ObjectInputStream(new >>>>>> ByteArrayInputStream(buffer.toByteArray())); >>>>>> element = (MyElement)inStream.readObject(); >>>>>> } >>>>>> } >>>>>> >>>>>> Result: >>>>>> >>>>>> Exception in thread "main" java.io.InvalidClassException: >>>>>> ; no valid constructor >>>>>> at >>>>>> >>>>> >>> >> java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147) >> >>>>>> at >>>>>> >> java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755) >>>>>> at >>>>>> >>>>> >>> >> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751) >> >>>>>> at >>>>> java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) >>>>>> at >>> java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) >>>>>> at .main(MyElement.java:29) >>>>> _______________________________________________ >>>>> To control your jdom-interest membership: >>>>> >> http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com > > Hi guys, > > thank you for your quick responses. I will try out the solution with > the altered CloneBase class. > > Kind Regards > > Bjoern > > -- > iSYS Software GmbH > > Bj?rn Buchner > > Tel: +49 (0) 89 46 23 28-0 | Fax (0) 89 46 23 28-14 > email: b.buchner at isys-software.de > Grillparzerstr. 10 | D-81675 Muenchen > www.isys-software.de > > Sitz der Gesellschaft: M?nchen | HRB 111760 > Geschaeftsfuehrer: Prof. Dr. Peter Mandl und Michael Sailer > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com The updated version is working for me. Thank you Rolf. Kind Regards Bjoern -- iSYS Software GmbH Bj?rn Buchner Tel: +49 (0) 89 46 23 28-0 | Fax (0) 89 46 23 28-14 email: b.buchner at isys-software.de Grillparzerstr. 10 | D-81675 Muenchen www.isys-software.de Sitz der Gesellschaft: M?nchen | HRB 111760 Geschaeftsfuehrer: Prof. Dr. Peter Mandl und Michael Sailer From jdom at tuis.net Fri Aug 10 03:57:24 2012 From: jdom at tuis.net (Rolf Lear) Date: Fri, 10 Aug 2012 06:57:24 -0400 Subject: [jdom-interest] Serialization Trouble through Inheritance Message-ID: Excellent. It was quite a headscratcher.... I will start the 2.0.3 release process. RolfBj?rn Buchner wrote:Am Freitag, 10. August 2012 08:15:09 schrieb Bj?rn Buchner: > Am Donnerstag, 9. August 2012 18:23:03 schrieb Rolf Lear: >> Hmmm... in a moment of daftness, I attached the wrong file (more >> haste... >> less speed). >> >> here is the working CloneBase file. >> >> >> >> Rolf >> >> On Thu, 09 Aug 2012 11:51:38 -0400, Rolf Lear wrote: >>> Hi Bj?rn, Oliver >>> >>> I have identified what the problem is...... this is not actually a Java >>> bug, but it describes what the JDOM bug is... I think.... >>> >>> http://bugs.sun.com/view_bug.do?bug_id=6522514 >>> >>> What this implies is that there is an issue in the permissions of the >> JDOM >>> element hierarchy. >>> >>> in my understanding, it goes like this.... >>> >>> org.jdom2.Element extends org.jdom2.Content. >>> org.jdom2.Content extends org.jdom2.CloneBase. >>> org.jdom2.CloneBase is a package-private (not public) class, and >> CloneBase >>> has no declared constructor (it has the default no-arg constructor). >>> >>> Your class 'MyElement' is not in the org.jdom2 package, so, it cannot >>> 'see' the no-arg constructor for (package private) org.jdom2.CloneBase. >>> >>> Thus the MyElement class cannot be de-serialized. >>> >>> I have 'proven' that this is the logic fault by putting the MyElement >>> class in the org.jdom2 package, and then, miraculously, the code works. >>> When I get home I will try it again but instead with a 'protected' >> no-arg >>> constructor on org.jdom2.CloneBase, and the MyElement class in some >> other >>> package..... actually, I have just tried it now, and it works..... >>> >>> Thus, there are two work-arounds: >>>?? - putting your MyElement code in the org.jdom2 package.... >>>?? - using the attached org.jdom2.CloneBase class which has a protected >>> no-arg constructor. >>> >>> >>> I have created a new issue (#88), and I have attached a working >> CloneBase >>> class you can add to your project temporarily..... >>> >>> I will push out JDOM 2.0.3 >>> >>> Rolf >>> >>> >>> >>> >>> On Thu, 9 Aug 2012 11:03:52 -0400, Oliver Ruebenacker >>> >>> wrote: >>>> Hello, >>>> >>>>??? Rolf, it shouldn't be necessary to add these methods. >>>> >>>>??? Bj?rn, can you check the import statement for Element? >>>> >>>>?????? Take care >>>>?????? Oliver >>>> >>>> On Thu, Aug 9, 2012 at 10:37 AM, Rolf Lear wrote: >>>>> >>>>> Hi Bj?rn >>>>> >>>>> I don't have my 'JDOM Laptop' with me at the moment, so I can't >>>>> easily >>>>> reproduce your problem, but, I suspect this is just an issue of >>>>> implementing your own read/write object methods. >>>>> >>>>> What happens if you add the following methods to your 'MyElement' >>> class? >>>>> I >>>>> believe this should fix things..... try it... :-) >>>>> >>>>> >>>>> >>>>>????????? /** >>>>>?????????? * Serialize out the MyElement. >>>>>?????????? * >>>>>?????????? * @serialData >>>>>?????????? * The Stream protocol is: >>>>>?????????? *
    >>>>>?????????? *??
  1. Write the super Element class out... >>>>>?????????? *
>>>>>?????????? * >>>>>?????????? * @param out where to write the Element to. >>>>>?????????? * @throws IOException if there is a writing problem. >>>>>?????????? */ >>>>>????????? private void writeObject(final ObjectOutputStream out) >>>>> throws >>>>>????????? IOException >>>>> { >>>>>????????????????? out.defaultWriteObject(); >>>>>????????? } >>>>> >>>>>????????? /** >>>>>?????????? * Read a MyElement off the ObjectInputStream. >>>>>?????????? * >>>>>?????????? * @see #writeObject(ObjectOutputStream) >>>>>?????????? * @param in where to read the Element from. >>>>>?????????? * @throws IOException if there is a reading problem. >>>>>?????????? * @throws ClassNotFoundException when a class cannot be >>>>> found >>>>>?????????? */ >>>>>????????? private void readObject(final ObjectInputStream in) >>>>>????????????????????????? throws IOException, ClassNotFoundException { >>>>>????????????????? in.defaultReadObject(); >>>>>????????? } >>>>> >>>>> >>>>> Rolf >>>>> >>>>> >>>>> >>>>> On Thu, 09 Aug 2012 16:08:48 +0200, Bj?rn Buchner >>>>> wrote: >>>>>> Hi Folks, >>>>>> >>>>>> I am using the JDOM 2.0.2 release and experienced some trouble when >> it >>>>>> comes to serialization. >>>>>> >>>>>> De-/serializing an Element object through the standard >>>>>> ObjectOutput/InputStream is no problem. Trouble starts when I try to >>>>>> deserialize an object of a class that inherits from Element. >>>>>> >>>>>> It always ends with a InvalidClassException: no valid constructor. >>>>>> Normally this indicates that JRE is missing a public default >>>>>> constructor, but as you can see in the example below the subclass >>>>>> has a default constructor. >>>>>> >>>>>> Thanks in advance for your help >>>>>> >>>>>> Example code: >>>>>> >>>>>> public class MyElement extends Element { >>>>>> >>>>>>?????? private static final long serialVersionUID = >>> -4220756491425652053L; >>>>>> >>>>>>?????? public MyElement() { >>>>>>?????????? super(); >>>>>>?????? } >>>>>> >>>>>> >>>>>>?????? public static void main(String ... args) throws IOException, >>>>>> ClassNotFoundException { >>>>>>????????? ByteArrayOutputStream buffer = new ByteArrayOutputStream(); >>>>>>????????? ObjectOutputStream outStream = new >> ObjectOutputStream(buffer); >>>>>> >>>>>>????????? MyElement element = new MyElement(); >>>>>> >>>>>>????????? outStream.writeObject(element); >>>>>>????????? outStream.flush(); >>>>>>????????? ObjectInputStream inStream = new ObjectInputStream(new >>>>>> ByteArrayInputStream(buffer.toByteArray())); >>>>>>????????? element = (MyElement)inStream.readObject(); >>>>>>?????? } >>>>>> } >>>>>> >>>>>> Result: >>>>>> >>>>>> Exception in thread "main" java.io.InvalidClassException: >>>>>> ; no valid constructor >>>>>>?????? at >>>>>> >>>>> >>> >> java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147) >> >>>>>>?????? at >>>>>> >> java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755) >>>>>>?????? at >>>>>> >>>>> >>> >> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751) >> >>>>>>?????? at >>>>> java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) >>>>>>?????? at >>> java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) >>>>>>?????? at .main(MyElement.java:29) >>>>> _______________________________________________ >>>>> To control your jdom-interest membership: >>>>> >> http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com > > Hi guys, > > thank you for your quick responses. I will try out the solution with > the altered CloneBase class. > > Kind Regards > > Bjoern > > -- > iSYS Software GmbH > > Bj?rn Buchner > > Tel: +49 (0) 89 46 23 28-0 | Fax? (0) 89 46 23 28-14 > email: b.buchner at isys-software.de > Grillparzerstr. 10 | D-81675 Muenchen > www.isys-software.de > > Sitz der Gesellschaft: M?nchen | HRB 111760 > Geschaeftsfuehrer: Prof. Dr. Peter Mandl und Michael Sailer > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com The updated version is working for me. Thank you Rolf. Kind Regards Bjoern -- iSYS Software GmbH Bj?rn Buchner Tel: +49 (0) 89 46 23 28-0 | Fax? (0) 89 46 23 28-14 email: b.buchner at isys-software.de Grillparzerstr. 10 | D-81675 Muenchen www.isys-software.de Sitz der Gesellschaft: M?nchen | HRB 111760 Geschaeftsfuehrer: Prof. Dr. Peter Mandl und Michael Sailer -------------- next part -------------- An HTML attachment was scrubbed... URL: From jdom at tuis.net Sat Aug 11 12:37:04 2012 From: jdom at tuis.net (Rolf Lear) Date: Sat, 11 Aug 2012 15:37:04 -0400 Subject: [jdom-interest] Fixed - Re: Serialization Trouble through Inheritance In-Reply-To: References: Message-ID: <5026B460.4090601@tuis.net> Hi Bj?rn, everyone. I have just committed a fix for this issue. This issue affects only people who serialize *subclasses* of the JDOM core classes (like custom subclasses of Element, Text, etc.). The fix for this issue is 'trivial' and has no negative impact on any compatibility requirements. On the other hand, the commit includes a number of new classes that support the test-cases for the fix. Like previous issues that have been identified in JDOM 2.x, I will issue a hotfix package on GitHub, and then, in a short while (in this case, 3 weeks) issue a new version of JDOM (in this case, 2.0.3). Thus, I have uploaded the 'hotfix' to GitHub here: https://github.com/downloads/hunterhacker/jdom/jdom-2.x-issue88.zip and at month-end (August 31st or September 1st or 2nd) I will do a full release of JDOM 2.0.3. This allows an opportunity for some some other potential issues to be identified and fixed without having a flood of new versions. If you have any issues, suggestions, questions (even Javadoc comment issues) then please speak up so that they can be fixed in the upcoming release. Thanks all Rolf On 10/08/2012 6:57 AM, Rolf Lear wrote: > Excellent. It was quite a headscratcher.... > > I will start the 2.0.3 release process. > > Rolf > > Bj?rn Buchner wrote: > Am Freitag, 10. August 2012 08:15:09 schrieb Bj?rn Buchner: > > Am Donnerstag, 9. August 2012 18:23:03 schrieb Rolf Lear: > >> Hmmm... in a moment of daftness, I attached the wrong file (more > >> haste... > >> less speed). > >> > >> here is the working CloneBase file. > >> > >> > >> > >> Rolf > >> > >> On Thu, 09 Aug 2012 11:51:38 -0400, Rolf Lear wrote: > >>> Hi Bj?rn, Oliver > >>> > >>> I have identified what the problem is...... this is not actually a Java > >>> bug, but it describes what the JDOM bug is... I think.... > >>> > >>> http://bugs.sun.com/view_bug.do?bug_id=6522514 > >>> > >>> What this implies is that there is an issue in the permissions of the > >> JDOM > >>> element hierarchy. > >>> > >>> in my understanding, it goes like this.... > >>> > >>> org.jdom2.Element extends org.jdom2.Content. > >>> org.jdom2.Content extends org.jdom2.CloneBase. > >>> org.jdom2.CloneBase is a package-private (not public) class, and > >> CloneBase > >>> has no declared constructor (it has the default no-arg constructor). > >>> > >>> Your class 'MyElement' is not in the org.jdom2 package, so, it cannot > >>> 'see' the no-arg constructor for (package private) org.jdom2.CloneBase. > >>> > >>> Thus the MyElement class cannot be de-serialized. > >>> > >>> I have 'proven' that this is the logic fault by putting the MyElement > >>> class in the org.jdom2 package, and then, miraculously, the code works. > >>> When I get home I will try it again but instead with a 'protected' > >> no-arg > >>> constructor on org.jdom2.CloneBase, and the MyElement class in some > >> other > >>> package..... actually, I have just tried it now, and it works..... > >>> > >>> Thus, there are two work-arounds: > >>> - putting your MyElement code in the org.jdom2 package.... > >>> - using the attached org.jdom2.CloneBase class which has a protected > >>> no-arg constructor. > >>> > >>> > >>> I have created a new issue (#88), and I have attached a working > >> CloneBase > >>> class you can add to your project temporarily..... > >>> > >>> I will push out JDOM 2.0.3 > >>> > >>> Rolf > >>> > >>> > >>> > >>> > >>> On Thu, 9 Aug 2012 11:03:52 -0400, Oliver Ruebenacker > >>> > >>> wrote: > >>>> Hello, > >>>> > >>>> Rolf, it shouldn't be necessary to add these methods. > >>>> > >>>> Bj?rn, can you check the import statement for Element? > >>>> > >>>> Take care > >>>> Oliver > >>>> > >>>> On Thu, Aug 9, 2012 at 10:37 AM, Rolf Lear wrote: > >>>>> > >>>>> Hi Bj?rn > >>>>> > >>>>> I don't have my 'JDOM Laptop' with me at the moment, so I can't > >>>>> easily > >>>>> reproduce your problem, but, I suspect this is just an issue of > >>>>> implementing your own read/write object methods. > >>>>> > >>>>> What happens if you add the following methods to your 'MyElement' > >>> class? > >>>>> I > >>>>> believe this should fix things..... try it... :-) > >>>>> > >>>>> > >>>>> > >>>>> /** > >>>>> * Serialize out the MyElement. > >>>>> * > >>>>> * @serialData > >>>>> * The Stream protocol is: > >>>>> *
    > >>>>> *
  1. Write the super Element class out... > >>>>> *
> >>>>> * > >>>>> * @param out where to write the Element to. > >>>>> * @throws IOException if there is a writing problem. > >>>>> */ > >>>>> private void writeObject(final ObjectOutputStream out) > >>>>> throws > >>>>> IOException > >>>>> { > >>>>> out.defaultWriteObject(); > >>>>> } > >>>>> > >>>>> /** > >>>>> * Read a MyElement off the ObjectInputStream. > >>>>> * > >>>>> * @see #writeObject(ObjectOutputStream) > >>>>> * @param in where to read the Element from. > >>>>> * @throws IOException if there is a reading problem. > >>>>> * @throws ClassNotFoundException when a class cannot be > >>>>> found > >>>>> */ > >>>>> private void readObject(final ObjectInputStream in) > >>>>> throws IOException, ClassNotFoundException { > >>>>> in.defaultReadObject(); > >>>>> } > >>>>> > >>>>> > >>>>> Rolf > >>>>> > >>>>> > >>>>> > >>>>> On Thu, 09 Aug 2012 16:08:48 +0200, Bj?rn Buchner > >>>>> wrote: > >>>>>> Hi Folks, > >>>>>> > >>>>>> I am using the JDOM 2.0.2 release and experienced some trouble when > >> it > >>>>>> comes to serialization. > >>>>>> > >>>>>> De-/serializing an Element object through the standard > >>>>>> ObjectOutput/InputStream is no problem. Trouble starts when I try to > >>>>>> deserialize an object of a class that inherits from Element. > >>>>>> > >>>>>> It always ends with a InvalidClassException: no valid constructor. > >>>>>> Normally this indicates that JRE is missing a public default > >>>>>> constructor, but as you can see in the example below the subclass > >>>>>> has a default constructor. > >>>>>> > >>>>>> Thanks in advance for your help > >>>>>> > >>>>>> Example code: > >>>>>> > >>>>>> public class MyElement extends Element { > >>>>>> > >>>>>> private static final long serialVersionUID = > >>> -4220756491425652053L; > >>>>>> > >>>>>> public MyElement() { > >>>>>> super(); > >>>>>> } > >>>>>> > >>>>>> > >>>>>> public static void main(String ... args) throws IOException, > >>>>>> ClassNotFoundException { > >>>>>> ByteArrayOutputStream buffer = new ByteArrayOutputStream(); > >>>>>> ObjectOutputStream outStream = new > >> ObjectOutputStream(buffer); > >>>>>> > >>>>>> MyElement element = new MyElement(); > >>>>>> > >>>>>> outStream.writeObject(element); > >>>>>> outStream.flush(); > >>>>>> ObjectInputStream inStream = new ObjectInputStream(new > >>>>>> ByteArrayInputStream(buffer.toByteArray())); > >>>>>> element = (MyElement)inStream.readObject(); > >>>>>> } > >>>>>> } > >>>>>> > >>>>>> Result: > >>>>>> > >>>>>> Exception in thread "main" java.io.InvalidClassException: > >>>>>> ; no valid constructor > >>>>>> at > >>>>>> > >>>>> > >>> > >> > java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147) > >> > >>>>>> at > >>>>>> > >> java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755) > >>>>>> at > >>>>>> > >>>>> > >>> > >> > java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751) > >> > >>>>>> at > >>>>> java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) > >>>>>> at > >>> java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) > >>>>>> at .main(MyElement.java:29) > >>>>> _______________________________________________ > >>>>> To control your jdom-interest membership: > >>>>> > >> http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com > > > > Hi guys, > > > > thank you for your quick responses. I will try out the solution with > > the altered CloneBase class. > > > > Kind Regards > > > > Bjoern > > > > -- > > iSYS Software GmbH > > > > Bj?rn Buchner > > > > Tel: +49 (0) 89 46 23 28-0 | Fax (0) 89 46 23 28-14 > > email: b.buchner at isys-software.de > > Grillparzerstr. 10 | D-81675 Muenchen > > www.isys-software.de > > > > Sitz der Gesellschaft: M?nchen | HRB 111760 > > Geschaeftsfuehrer: Prof. Dr. Peter Mandl und Michael Sailer > > _______________________________________________ > > To control your jdom-interest membership: > > http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com > > The updated version is working for me. Thank you Rolf. > > Kind Regards > > Bjoern > > -- > iSYS Software GmbH > > Bj?rn Buchner > > Tel: +49 (0) 89 46 23 28-0 | Fax (0) 89 46 23 28-14 > email: b.buchner at isys-software.de > Grillparzerstr. 10 | D-81675 Muenchen > www.isys-software.de > > Sitz der Gesellschaft: M?nchen | HRB 111760 > Geschaeftsfuehrer: Prof. Dr. Peter Mandl und Michael Sailer > > > > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com > From jdom at tuis.net Mon Aug 20 10:34:58 2012 From: jdom at tuis.net (Rolf Lear) Date: Mon, 20 Aug 2012 13:34:58 -0400 Subject: [jdom-interest] jdom2 migration issue In-Reply-To: <001301cd7eec$9d795a90$d86c0fb0$@synesis7.com> References: <001301cd7eec$9d795a90$d86c0fb0$@synesis7.com> Message-ID: <5738f723b41b7c2a700ff4e2d37b1afa@tuis.net> Hi Craig. There must be some other imports from the org.jdom package (as well as org.jdom2....). The error message you are getting would be impossible unless you have those imports. Something is wrong in your imports.... and your build path must have some old JDOM classes from places other than just the old JDOM jar. Finally, it is normal in GUI-type development tools, (eclipse, IntelliJ, etc) to exclude the package on field names.... i.e. the line: protected org.jdom2.Document document; would not normally be created by Eclipse/IntelliJ unless your class was already using the org.jdom.Document version somewhere. You should probably replace the line with: protected Document document; and ensure that you can import Document from org.jdom2 with import org.jdom2.Document; Bottom line is that you still have old JDOM classes in your build path, and the copde you have shown us us using *both* Document versions (org.jdom, as well as org.jdom2). Rolf On Mon, 20 Aug 2012 09:58:15 -0600, "Craig Christophersen" wrote: > Hello; > > I have been trying to migrate to Jdom2 in an application. I have followed > the migration guide but get a type mismatch error. > > Snippit below: > > protected org.jdom2.Document document; > > > > private String str = null; > > private String dmString = ""; > > String f = "f"; > > String t = "t"; > > protected DocType dt; > > /** > > * Read the specified File and parse it to create a JDOM tree > > **/ > > public ReadDmFile(File dmFile)// throws IOException, JDOMException { > > { > > System.out.println("File in ReadDm X: " + dmFile); > > > > try { > > SAXBuilder builder = > > new SAXBuilder(); //"org.apache.xerces.parsers.SAXParser" > > > > // Parse the specified file and convert it to a JDOM document > > builder.setIgnoringElementContentWhitespace(true); > > document = builder.build(dmFile); > > > > > > > > On last line I get "Type mismatch: cannot convert from org.jdom2.Document > to > org.jdom.Document" > > The old jdom jar is removed from this project. > > Any help would be appreciated. > > > > Thanks, > > > > > > Craig Christophersen > > Software Developer > > Synesis7 > > craigch at synesis7.com From jdom at tuis.net Mon Aug 20 11:24:32 2012 From: jdom at tuis.net (Rolf Lear) Date: Mon, 20 Aug 2012 14:24:32 -0400 Subject: [jdom-interest] jdom2 migration issue In-Reply-To: <002601cd7f00$34898e10$9d9caa30$@synesis7.com> References: <001301cd7eec$9d795a90$d86c0fb0$@synesis7.com> <5738f723b41b7c2a700ff4e2d37b1afa@tuis.net> <002601cd7f00$34898e10$9d9caa30$@synesis7.com> Message-ID: <15bfe0284f1a0023911846063222b632@tuis.net> In eclipse, edit your file, then type shift-ctrl-T Then type org.jdom.Document In the box below, you have all the locations of jdom 1.x Documents. As a double-check, can you copy/paste the entire import section in your class.... I am convinced there must be an import from org.jdom.* or something. P.S. when you reply, do a reply-all, and I will get your answer faster..... Rolf On Mon, 20 Aug 2012 12:18:29 -0600, "Craig Christophersen" wrote: > Hello Rolf; Thank you for your reply. I have again looked thru stuff and > found no old jdom. Are there known jars(I use several apache) that would > include jdom classes??? I am using eclipse. > > > -----Original Message----- > From: Rolf Lear [mailto:jdom at tuis.net] > Sent: Monday, August 20, 2012 11:35 AM > To: Craig Christophersen > Cc: jdom-interest at jdom.org > Subject: Re: [jdom-interest] jdom2 migration issue > > > Hi Craig. > > There must be some other imports from the org.jdom package (as well as > org.jdom2....). > > The error message you are getting would be impossible unless you have > those imports. > > Something is wrong in your imports.... and your build path must have some > old JDOM classes from places other than just the old JDOM jar. > > Finally, it is normal in GUI-type development tools, (eclipse, IntelliJ, > etc) to exclude the package on field names.... i.e. the line: > > protected org.jdom2.Document document; > > would not normally be created by Eclipse/IntelliJ unless your class was > already using the org.jdom.Document version somewhere. You should probably > replace the line with: > > protected Document document; > > and ensure that you can import Document from org.jdom2 with > > import org.jdom2.Document; > > Bottom line is that you still have old JDOM classes in your build path, > and the copde you have shown us us using *both* Document versions > (org.jdom, as well as org.jdom2). > > Rolf > > > > > > On Mon, 20 Aug 2012 09:58:15 -0600, "Craig Christophersen" > wrote: >> Hello; >> >> I have been trying to migrate to Jdom2 in an application. I have > followed >> the migration guide but get a type mismatch error. >> >> Snippit below: >> >> protected org.jdom2.Document document; >> >> >> >> private String str = null; >> >> private String dmString = ""; >> >> String f = "f"; >> >> String t = "t"; >> >> protected DocType dt; >> >> /** >> >> * Read the specified File and parse it to create a JDOM tree >> >> **/ >> >> public ReadDmFile(File dmFile)// throws IOException, JDOMException >> { >> >> { >> >> System.out.println("File in ReadDm X: " + dmFile); >> >> >> >> try { >> >> SAXBuilder builder = >> >> new SAXBuilder(); //"org.apache.xerces.parsers.SAXParser" >> >> >> >> // Parse the specified file and convert it to a JDOM document >> >> builder.setIgnoringElementContentWhitespace(true); >> >> document = builder.build(dmFile); >> >> >> >> >> >> >> >> On last line I get "Type mismatch: cannot convert from > org.jdom2.Document >> to >> org.jdom.Document" >> >> The old jdom jar is removed from this project. >> >> Any help would be appreciated. >> >> >> >> Thanks, >> >> >> >> >> >> Craig Christophersen >> >> Software Developer >> >> Synesis7 >> >> craigch at synesis7.com From craigch at synesis7.com Mon Aug 20 11:51:33 2012 From: craigch at synesis7.com (Craig Christophersen) Date: Mon, 20 Aug 2012 12:51:33 -0600 Subject: [jdom-interest] jdom2 migration issue In-Reply-To: <15bfe0284f1a0023911846063222b632@tuis.net> References: <001301cd7eec$9d795a90$d86c0fb0$@synesis7.com> <5738f723b41b7c2a700ff4e2d37b1afa@tuis.net> <002601cd7f00$34898e10$9d9caa30$@synesis7.com> <15bfe0284f1a0023911846063222b632@tuis.net> Message-ID: <002701cd7f04$d7d52800$877f7800$@synesis7.com> In the open type window it does show another project in eclipse with "org.jdom.Document". But it is another project that I will migrate also once I get it working in this project. The other project is not referenced by the current project. There are 8 classes in the project that use jdom. Below is a typical import: import java.io.*; import java.util.*; import java.util.regex.Pattern; import org.jdom2.*; import org.jdom2.filter.ElementFilter; import org.jdom2.input.SAXBuilder; And another class imports: import java.io.*; import java.util.*; import java.io.File.*; import java.io.IOException; import java.util.concurrent.ConcurrentLinkedQueue; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.JaxenException; import org.jdom2.output.*; import org.jdom2.*; import org.jdom2.filter.ElementFilter; import org.jdom2.filter.ContentFilter; import org.jdom2.input.*; import org.jdom2.xpath.*; -----Original Message----- From: Rolf Lear [mailto:jdom at tuis.net] Sent: Monday, August 20, 2012 12:25 PM To: Craig Christophersen; Jdom interest Subject: RE: [jdom-interest] jdom2 migration issue In eclipse, edit your file, then type shift-ctrl-T Then type org.jdom.Document In the box below, you have all the locations of jdom 1.x Documents. As a double-check, can you copy/paste the entire import section in your class.... I am convinced there must be an import from org.jdom.* or something. P.S. when you reply, do a reply-all, and I will get your answer faster..... Rolf On Mon, 20 Aug 2012 12:18:29 -0600, "Craig Christophersen" wrote: > Hello Rolf; Thank you for your reply. I have again looked thru stuff and > found no old jdom. Are there known jars(I use several apache) that would > include jdom classes??? I am using eclipse. > > > -----Original Message----- > From: Rolf Lear [mailto:jdom at tuis.net] > Sent: Monday, August 20, 2012 11:35 AM > To: Craig Christophersen > Cc: jdom-interest at jdom.org > Subject: Re: [jdom-interest] jdom2 migration issue > > > Hi Craig. > > There must be some other imports from the org.jdom package (as well as > org.jdom2....). > > The error message you are getting would be impossible unless you have > those imports. > > Something is wrong in your imports.... and your build path must have some > old JDOM classes from places other than just the old JDOM jar. > > Finally, it is normal in GUI-type development tools, (eclipse, IntelliJ, > etc) to exclude the package on field names.... i.e. the line: > > protected org.jdom2.Document document; > > would not normally be created by Eclipse/IntelliJ unless your class was > already using the org.jdom.Document version somewhere. You should probably > replace the line with: > > protected Document document; > > and ensure that you can import Document from org.jdom2 with > > import org.jdom2.Document; > > Bottom line is that you still have old JDOM classes in your build path, > and the copde you have shown us us using *both* Document versions > (org.jdom, as well as org.jdom2). > > Rolf > > > > > > On Mon, 20 Aug 2012 09:58:15 -0600, "Craig Christophersen" > wrote: >> Hello; >> >> I have been trying to migrate to Jdom2 in an application. I have > followed >> the migration guide but get a type mismatch error. >> >> Snippit below: >> >> protected org.jdom2.Document document; >> >> >> >> private String str = null; >> >> private String dmString = ""; >> >> String f = "f"; >> >> String t = "t"; >> >> protected DocType dt; >> >> /** >> >> * Read the specified File and parse it to create a JDOM tree >> >> **/ >> >> public ReadDmFile(File dmFile)// throws IOException, JDOMException >> { >> >> { >> >> System.out.println("File in ReadDm X: " + dmFile); >> >> >> >> try { >> >> SAXBuilder builder = >> >> new SAXBuilder(); //"org.apache.xerces.parsers.SAXParser" >> >> >> >> // Parse the specified file and convert it to a JDOM document >> >> builder.setIgnoringElementContentWhitespace(true); >> >> document = builder.build(dmFile); >> >> >> >> >> >> >> >> On last line I get "Type mismatch: cannot convert from > org.jdom2.Document >> to >> org.jdom.Document" >> >> The old jdom jar is removed from this project. >> >> Any help would be appreciated. >> >> >> >> Thanks, >> >> >> >> >> >> Craig Christophersen >> >> Software Developer >> >> Synesis7 >> >> craigch at synesis7.com From jdom at tuis.net Mon Aug 20 12:02:04 2012 From: jdom at tuis.net (Rolf Lear) Date: Mon, 20 Aug 2012 15:02:04 -0400 Subject: [jdom-interest] jdom2 migration issue In-Reply-To: <002701cd7f04$d7d52800$877f7800$@synesis7.com> References: <001301cd7eec$9d795a90$d86c0fb0$@synesis7.com> <5738f723b41b7c2a700ff4e2d37b1afa@tuis.net> <002601cd7f00$34898e10$9d9caa30$@synesis7.com> <15bfe0284f1a0023911846063222b632@tuis.net> <002701cd7f04$d7d52800$877f7800$@synesis7.com> Message-ID: <11346c591a11cf7f5f1f782fce5c5aa2@tuis.net> Right, then the next thing to do is to worry about the protected variable 'document'. In your code you have protected org.jdom2.Document document; I had assumed that this was the same variable as the one in the line: document = builder.build(dmFile); But, now I am not so sure.... perhaps in this case the document in the build line is some other document variable with the same name from a super class or something. So, what happens if you replace the build line: document = builder.build(dmFile); with: final org.jdom2.Document mydoc = builder.build(dmFile); document = mydoc; Rolf On Mon, 20 Aug 2012 12:51:33 -0600, "Craig Christophersen" wrote: > In the open type window it does show another project in eclipse with > "org.jdom.Document". But it is another project that I will migrate also > once I get it working in this project. The other project is not referenced > by the current project. > > There are 8 classes in the project that use jdom. Below is a typical > import: > > import java.io.*; > import java.util.*; > import java.util.regex.Pattern; > > import org.jdom2.*; > import org.jdom2.filter.ElementFilter; > import org.jdom2.input.SAXBuilder; > > And another class imports: > > import java.io.*; > import java.util.*; > import java.io.File.*; > import java.io.IOException; > import java.util.concurrent.ConcurrentLinkedQueue; > > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; > > import org.jaxen.JaxenException; > > import org.jdom2.output.*; > import org.jdom2.*; > import org.jdom2.filter.ElementFilter; > import org.jdom2.filter.ContentFilter; > import org.jdom2.input.*; > import org.jdom2.xpath.*; > > -----Original Message----- > From: Rolf Lear [mailto:jdom at tuis.net] > Sent: Monday, August 20, 2012 12:25 PM > To: Craig Christophersen; Jdom interest > Subject: RE: [jdom-interest] jdom2 migration issue > > > In eclipse, edit your file, then type shift-ctrl-T > Then type org.jdom.Document > > In the box below, you have all the locations of jdom 1.x Documents. > > As a double-check, can you copy/paste the entire import section in your > class.... I am convinced there must be an import from org.jdom.* or > something. > > P.S. when you reply, do a reply-all, and I will get your answer > faster..... > > Rolf > > > On Mon, 20 Aug 2012 12:18:29 -0600, "Craig Christophersen" > wrote: >> Hello Rolf; Thank you for your reply. I have again looked thru stuff > and >> found no old jdom. Are there known jars(I use several apache) that > would >> include jdom classes??? I am using eclipse. >> >> >> -----Original Message----- >> From: Rolf Lear [mailto:jdom at tuis.net] >> Sent: Monday, August 20, 2012 11:35 AM >> To: Craig Christophersen >> Cc: jdom-interest at jdom.org >> Subject: Re: [jdom-interest] jdom2 migration issue >> >> >> Hi Craig. >> >> There must be some other imports from the org.jdom package (as well as >> org.jdom2....). >> >> The error message you are getting would be impossible unless you have >> those imports. >> >> Something is wrong in your imports.... and your build path must have > some >> old JDOM classes from places other than just the old JDOM jar. >> >> Finally, it is normal in GUI-type development tools, (eclipse, IntelliJ, >> etc) to exclude the package on field names.... i.e. the line: >> >> protected org.jdom2.Document document; >> >> would not normally be created by Eclipse/IntelliJ unless your class was >> already using the org.jdom.Document version somewhere. You should > probably >> replace the line with: >> >> protected Document document; >> >> and ensure that you can import Document from org.jdom2 with >> >> import org.jdom2.Document; >> >> Bottom line is that you still have old JDOM classes in your build path, >> and the copde you have shown us us using *both* Document versions >> (org.jdom, as well as org.jdom2). >> >> Rolf >> >> >> >> >> >> On Mon, 20 Aug 2012 09:58:15 -0600, "Craig Christophersen" >> wrote: >>> Hello; >>> >>> I have been trying to migrate to Jdom2 in an application. I have >> followed >>> the migration guide but get a type mismatch error. >>> >>> Snippit below: >>> >>> protected org.jdom2.Document document; >>> >>> >>> >>> private String str = null; >>> >>> private String dmString = ""; >>> >>> String f = "f"; >>> >>> String t = "t"; >>> >>> protected DocType dt; >>> >>> /** >>> >>> * Read the specified File and parse it to create a JDOM tree >>> >>> **/ >>> >>> public ReadDmFile(File dmFile)// throws IOException, JDOMException >>> { >>> >>> { >>> >>> System.out.println("File in ReadDm X: " + dmFile); >>> >>> >>> >>> try { >>> >>> SAXBuilder builder = >>> >>> new SAXBuilder(); //"org.apache.xerces.parsers.SAXParser" >>> >>> >>> >>> // Parse the specified file and convert it to a JDOM document >>> >>> builder.setIgnoringElementContentWhitespace(true); >>> >>> document = builder.build(dmFile); >>> >>> >>> >>> >>> >>> >>> >>> On last line I get "Type mismatch: cannot convert from >> org.jdom2.Document >>> to >>> org.jdom.Document" >>> >>> The old jdom jar is removed from this project. >>> >>> Any help would be appreciated. >>> >>> >>> >>> Thanks, >>> >>> >>> >>> >>> >>> Craig Christophersen >>> >>> Software Developer >>> >>> Synesis7 >>> >>> craigch at synesis7.com From craigch at synesis7.com Mon Aug 20 13:00:16 2012 From: craigch at synesis7.com (Craig Christophersen) Date: Mon, 20 Aug 2012 14:00:16 -0600 Subject: [jdom-interest] jdom2 migration issue In-Reply-To: <11346c591a11cf7f5f1f782fce5c5aa2@tuis.net> References: <001301cd7eec$9d795a90$d86c0fb0$@synesis7.com> <5738f723b41b7c2a700ff4e2d37b1afa@tuis.net> <002601cd7f00$34898e10$9d9caa30$@synesis7.com> <15bfe0284f1a0023911846063222b632@tuis.net> <002701cd7f04$d7d52800$877f7800$@synesis7.com> <11346c591a11cf7f5f1f782fce5c5aa2@tuis.net> Message-ID: <002801cd7f0e$6dfc1880$49f44980$@synesis7.com> This is very peculiar. That line now compiles. But further down in the class is another method using "document" that will not(with the same type mismatch error). The line " Element root = document.getRootElement();? errors. Method: public String getWPNum() throws JDOMException { String wpNum = ""; Element root = document.getRootElement(); Element idstatus = (Element)root.getChild("idstatus"); Element status = (Element)idstatus.getChild("status"); Element remarks = (Element)status.getChild("remarks"); wpNum = remarks.getText(); if(wpNum.equals("")) { wpNum = "0"; } System.out.println("WPNum in Read DM: " + wpNum); return wpNum; } -----Original Message----- From: Rolf Lear [mailto:jdom at tuis.net] Sent: Monday, August 20, 2012 1:02 PM To: Craig Christophersen Cc: Jdom interest Subject: RE: [jdom-interest] jdom2 migration issue Right, then the next thing to do is to worry about the protected variable 'document'. In your code you have protected org.jdom2.Document document; I had assumed that this was the same variable as the one in the line: document = builder.build(dmFile); But, now I am not so sure.... perhaps in this case the document in the build line is some other document variable with the same name from a super class or something. So, what happens if you replace the build line: document = builder.build(dmFile); with: final org.jdom2.Document mydoc = builder.build(dmFile); document = mydoc; Rolf On Mon, 20 Aug 2012 12:51:33 -0600, "Craig Christophersen" wrote: > In the open type window it does show another project in eclipse with > "org.jdom.Document". But it is another project that I will migrate > also once I get it working in this project. The other project is not referenced > by the current project. > > There are 8 classes in the project that use jdom. Below is a typical > import: > > import java.io.*; > import java.util.*; > import java.util.regex.Pattern; > > import org.jdom2.*; > import org.jdom2.filter.ElementFilter; import > org.jdom2.input.SAXBuilder; > > And another class imports: > > import java.io.*; > import java.util.*; > import java.io.File.*; > import java.io.IOException; > import java.util.concurrent.ConcurrentLinkedQueue; > > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; > > import org.jaxen.JaxenException; > > import org.jdom2.output.*; > import org.jdom2.*; > import org.jdom2.filter.ElementFilter; import > org.jdom2.filter.ContentFilter; import org.jdom2.input.*; import > org.jdom2.xpath.*; > > -----Original Message----- > From: Rolf Lear [mailto:jdom at tuis.net] > Sent: Monday, August 20, 2012 12:25 PM > To: Craig Christophersen; Jdom interest > Subject: RE: [jdom-interest] jdom2 migration issue > > > In eclipse, edit your file, then type shift-ctrl-T Then type > org.jdom.Document > > In the box below, you have all the locations of jdom 1.x Documents. > > As a double-check, can you copy/paste the entire import section in > your class.... I am convinced there must be an import from org.jdom.* > or something. > > P.S. when you reply, do a reply-all, and I will get your answer > faster..... > > Rolf > > > On Mon, 20 Aug 2012 12:18:29 -0600, "Craig Christophersen" > wrote: >> Hello Rolf; Thank you for your reply. I have again looked thru stuff > and >> found no old jdom. Are there known jars(I use several apache) that > would >> include jdom classes??? I am using eclipse. >> >> >> -----Original Message----- >> From: Rolf Lear [mailto:jdom at tuis.net] >> Sent: Monday, August 20, 2012 11:35 AM >> To: Craig Christophersen >> Cc: jdom-interest at jdom.org >> Subject: Re: [jdom-interest] jdom2 migration issue >> >> >> Hi Craig. >> >> There must be some other imports from the org.jdom package (as well >> as org.jdom2....). >> >> The error message you are getting would be impossible unless you have >> those imports. >> >> Something is wrong in your imports.... and your build path must have > some >> old JDOM classes from places other than just the old JDOM jar. >> >> Finally, it is normal in GUI-type development tools, (eclipse, IntelliJ, >> etc) to exclude the package on field names.... i.e. the line: >> >> protected org.jdom2.Document document; >> >> would not normally be created by Eclipse/IntelliJ unless your class >> was already using the org.jdom.Document version somewhere. You should > probably >> replace the line with: >> >> protected Document document; >> >> and ensure that you can import Document from org.jdom2 with >> >> import org.jdom2.Document; >> >> Bottom line is that you still have old JDOM classes in your build >> path, and the copde you have shown us us using *both* Document >> versions (org.jdom, as well as org.jdom2). >> >> Rolf >> >> >> >> >> >> On Mon, 20 Aug 2012 09:58:15 -0600, "Craig Christophersen" >> wrote: >>> Hello; >>> >>> I have been trying to migrate to Jdom2 in an application. I have >> followed >>> the migration guide but get a type mismatch error. >>> >>> Snippit below: >>> >>> protected org.jdom2.Document document; >>> >>> >>> >>> private String str = null; >>> >>> private String dmString = ""; >>> >>> String f = "f"; >>> >>> String t = "t"; >>> >>> protected DocType dt; >>> >>> /** >>> >>> * Read the specified File and parse it to create a JDOM tree >>> >>> **/ >>> >>> public ReadDmFile(File dmFile)// throws IOException, >>> JDOMException >>> { >>> >>> { >>> >>> System.out.println("File in ReadDm X: " + dmFile); >>> >>> >>> >>> try { >>> >>> SAXBuilder builder = >>> >>> new SAXBuilder(); //"org.apache.xerces.parsers.SAXParser" >>> >>> >>> >>> // Parse the specified file and convert it to a JDOM >>> document >>> >>> builder.setIgnoringElementContentWhitespace(true); >>> >>> document = builder.build(dmFile); >>> >>> >>> >>> >>> >>> >>> >>> On last line I get "Type mismatch: cannot convert from >> org.jdom2.Document >>> to >>> org.jdom.Document" >>> >>> The old jdom jar is removed from this project. >>> >>> Any help would be appreciated. >>> >>> >>> >>> Thanks, >>> >>> >>> >>> >>> >>> Craig Christophersen >>> >>> Software Developer >>> >>> Synesis7 >>> >>> craigch at synesis7.com From jdom at tuis.net Mon Aug 20 13:06:29 2012 From: jdom at tuis.net (Rolf Lear) Date: Mon, 20 Aug 2012 16:06:29 -0400 Subject: [jdom-interest] jdom2 migration issue Message-ID: <5lub6cjn4pyoumdaboc18crm.1345493189532@email.android.com> In eclipse do a 'clean' on your project... Perhaps there are some 'vestiges' of a previous eclipse build. Rolf Craig Christophersen wrote:This is very peculiar.? That line now compiles. But further down in the class is another method using? "document" that will not(with the same type mismatch error). The line " Element root = document.getRootElement();? errors. Method: ? public String getWPNum() throws JDOMException { ??????? String wpNum = ""; ??????????? Element root = document.getRootElement(); ??????????? Element idstatus = (Element)root.getChild("idstatus"); ??????????? Element status = (Element)idstatus.getChild("status"); ??????????? Element remarks = (Element)status.getChild("remarks"); ??????????? wpNum = remarks.getText(); ??????????? if(wpNum.equals("")) { ?????????????? wpNum = "0"; ??????????? } ??????????? System.out.println("WPNum in Read DM: " + wpNum); ??????????????????? ??????? return wpNum; ??? } -----Original Message----- From: Rolf Lear [mailto:jdom at tuis.net] Sent: Monday, August 20, 2012 1:02 PM To: Craig Christophersen Cc: Jdom interest Subject: RE: [jdom-interest] jdom2 migration issue Right, then the next thing to do is to worry about the protected variable 'document'. In your code you have protected org.jdom2.Document document; I had assumed that this was the same variable as the one in the line: ??? document = builder.build(dmFile); But, now I am not so sure.... perhaps in this case the document in the build line is some other document variable with the same name from a super class or something. So, what happens if you replace the build line: ??? document = builder.build(dmFile); with: ??? final org.jdom2.Document mydoc = builder.build(dmFile); ??? document = mydoc; Rolf On Mon, 20 Aug 2012 12:51:33 -0600, "Craig Christophersen" wrote: > In the open type window it does show another project in eclipse with > "org.jdom.Document".? But it is another project that I will migrate > also once I get it working in this project.? The other project is not referenced > by the current project. > > There are 8 classes in the project that use jdom.? Below is a typical > import: > > import java.io.*; > import java.util.*; > import java.util.regex.Pattern; > > import org.jdom2.*; > import org.jdom2.filter.ElementFilter; import > org.jdom2.input.SAXBuilder; > > And another class imports: > > import java.io.*; > import java.util.*; > import java.io.File.*; > import java.io.IOException; > import java.util.concurrent.ConcurrentLinkedQueue; > > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; > > import org.jaxen.JaxenException; > > import org.jdom2.output.*; > import org.jdom2.*; > import org.jdom2.filter.ElementFilter; import > org.jdom2.filter.ContentFilter; import org.jdom2.input.*; import > org.jdom2.xpath.*; > > -----Original Message----- > From: Rolf Lear [mailto:jdom at tuis.net] > Sent: Monday, August 20, 2012 12:25 PM > To: Craig Christophersen; Jdom interest > Subject: RE: [jdom-interest] jdom2 migration issue > > > In eclipse, edit your file, then type shift-ctrl-T Then type > org.jdom.Document > > In the box below, you have all the locations of jdom 1.x Documents. > > As a double-check, can you copy/paste the entire import section in > your class.... I am convinced there must be an import from org.jdom.* > or something. > > P.S. when you reply, do a reply-all, and I will get your answer > faster..... > > Rolf > > > On Mon, 20 Aug 2012 12:18:29 -0600, "Craig Christophersen" > wrote: >> Hello Rolf; Thank you for your reply.? I have again looked thru stuff > and >> found no old jdom.? Are there known jars(I use several apache) that > would >> include jdom classes???? I am using eclipse. >> >> >> -----Original Message----- >> From: Rolf Lear [mailto:jdom at tuis.net] >> Sent: Monday, August 20, 2012 11:35 AM >> To: Craig Christophersen >> Cc: jdom-interest at jdom.org >> Subject: Re: [jdom-interest] jdom2 migration issue >> >> >> Hi Craig. >> >> There must be some other imports from the org.jdom package (as well >> as org.jdom2....). >> >> The error message you are getting would be impossible unless you have >> those imports. >> >> Something is wrong in your imports.... and your build path must have > some >> old JDOM classes from places other than just the old JDOM jar. >> >> Finally, it is normal in GUI-type development tools, (eclipse, IntelliJ, >> etc) to exclude the package on field names.... i.e. the line: >> >>???? protected org.jdom2.Document document; >> >> would not normally be created by Eclipse/IntelliJ unless your class >> was already using the org.jdom.Document version somewhere. You should > probably >> replace the line with: >> >>???? protected Document document; >> >> and ensure that you can import Document from org.jdom2 with >> >>???? import org.jdom2.Document; >> >> Bottom line is that you still have old JDOM classes in your build >> path, and the copde you have shown us us using *both* Document >> versions (org.jdom, as well as org.jdom2). >> >> Rolf >> >> >> >> >> >> On Mon, 20 Aug 2012 09:58:15 -0600, "Craig Christophersen" >> wrote: >>> Hello; >>> >>> I have been trying to migrate to Jdom2 in an application.? I have >> followed >>> the migration guide but get a type mismatch error. >>> >>> Snippit below: >>> >>>??? protected org.jdom2.Document document; >>> >>>? >>> >>>???? private String str = null; >>> >>>???? private String dmString = ""; >>> >>>???? String f = "f"; >>> >>>???? String t = "t"; >>> >>>???? protected DocType dt; >>> >>>???? /** >>> >>>????? * Read the specified File and parse it to create a JDOM tree >>> >>>????? **/ >>> >>>???? public ReadDmFile(File dmFile)// throws IOException, >>> JDOMException >>> { >>> >>>???? { >>> >>>???????? System.out.println("File in ReadDm X: " + dmFile); >>> >>>??????? >>> >>>???????? try { >>> >>>???????? SAXBuilder builder = >>> >>>???????????? new SAXBuilder(); //"org.apache.xerces.parsers.SAXParser" >>> >>>?????? >>> >>>???????? // Parse the specified file and convert it to a JDOM >>> document >>> >>>???????? builder.setIgnoringElementContentWhitespace(true); >>> >>>???????? document = builder.build(dmFile); >>> >>>? >>> >>>? >>> >>>? >>> >>> On last line I get "Type mismatch: cannot convert from >> org.jdom2.Document >>> to >>> org.jdom.Document" >>> >>> The old jdom jar is removed from this project. >>> >>> Any help would be appreciated. >>> >>>? >>> >>> Thanks, >>> >>>? >>> >>>? >>> >>> Craig Christophersen >>> >>> Software Developer >>> >>> Synesis7 >>> >>> craigch at synesis7.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From craigch at synesis7.com Mon Aug 20 13:22:15 2012 From: craigch at synesis7.com (Craig Christophersen) Date: Mon, 20 Aug 2012 14:22:15 -0600 Subject: [jdom-interest] jdom2 migration issue In-Reply-To: <5lub6cjn4pyoumdaboc18crm.1345493189532@email.android.com> References: <5lub6cjn4pyoumdaboc18crm.1345493189532@email.android.com> Message-ID: <002c01cd7f11$7f5f5c60$7e1e1520$@synesis7.com> Took two cleans to get it all clean. Changed back: final org.jdom2.Document mydoc = builder.build(dmFile); document = mydoc; to: document = builder.build(dmFile); in that one class. All now compiles. Thank you much for your help??I guess this was more of an eclipse and developer not cleaning his project enough issue. I look forward to running this application now, and learning more about the enhancements in jdom2. Thank you again, Craig From: Rolf Lear [mailto:jdom at tuis.net] Sent: Monday, August 20, 2012 2:06 PM To: craigch at synesis7.com Cc: jdom-interest at jdom.org Subject: RE: [jdom-interest] jdom2 migration issue In eclipse do a 'clean' on your project... Perhaps there are some 'vestiges' of a previous eclipse build. Rolf Craig Christophersen wrote: This is very peculiar. That line now compiles. But further down in the class is another method using "document" that will not(with the same type mismatch error). The line " Element root = document.getRootElement();? errors. Method: public String getWPNum() throws JDOMException { String wpNum = ""; Element root = document.getRootElement(); Element idstatus = (Element)root.getChild("idstatus"); Element status = (Element)idstatus.getChild("status"); Element remarks = (Element)status.getChild("remarks"); wpNum = remarks.getText(); if(wpNum.equals("")) { wpNum = "0"; } System.out.println("WPNum in Read DM: " + wpNum); return wpNum; } -----Original Message----- From: Rolf Lear [mailto:jdom at tuis.net] Sent: Monday, August 20, 2012 1:02 PM To: Craig Christophersen Cc: Jdom interest Subject: RE: [jdom-interest] jdom2 migration issue Right, then the next thing to do is to worry about the protected variable 'document'. In your code you have protected org.jdom2.Document document; I had assumed that this was the same variable as the one in the line: document = builder.build(dmFile); But, now I am not so sure.... perhaps in this case the document in the build line is some other document variable with the same name from a super class or something. So, what happens if you replace the build line: document = builder.build(dmFile); with: final org.jdom2.Document mydoc = builder.build(dmFile); document = mydoc; Rolf On Mon, 20 Aug 2012 12:51:33 -0600, "Craig Christophersen" wrote: > In the open type window it does show another project in eclipse with > "org.jdom.Document". But it is another project that I will migrate > also once I get it working in this project. The other project is not referenced > by the current project. > > There are 8 classes in the project that use jdom. Below is a typical > import: > > import java.io.*; > import java.util.*; > import java.util.regex.Pattern; > > import org.jdom2.*; > import org.jdom2.filter.ElementFilter; import > org.jdom2.input.SAXBuilder; > > And another class imports: > > import java.io.*; > import java.util.*; > import java.io.File.*; > import java.io.IOException; > import java.util.concurrent.ConcurrentLinkedQueue; > > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; > > import org.jaxen.JaxenException; > > import org.jdom2.output.*; > import org.jdom2.*; > import org.jdom2.filter.ElementFilter; import > org.jdom2.filter.ContentFilter; import org.jdom2.input.*; import > org.jdom2.xpath.*; > > -----Original Message----- > From: Rolf Lear [mailto:jdom at tuis.net] > Sent: Monday, August 20, 2012 12:25 PM > To: Craig Christophersen; Jdom interest > Subject: RE: [jdom-interest] jdom2 migration issue > > > In eclipse, edit your file, then type shift-ctrl-T Then type > org.jdom.Document > > In the box below, you have all the locations of jdom 1.x Documents. > > As a double-check, can you copy/paste the entire import section in > your class.... I am convinced there must be an import from org.jdom.* > or something. > > P.S. when you reply, do a reply-all, and I will get your answer > faster..... > > Rolf > > > On Mon, 20 Aug 2012 12:18:29 -0600, "Craig Christophersen" > wrote: >> Hello Rolf; Thank you for your reply. I have again looked thru stuff > and >> found no old jdom. Are there known jars(I use several apache) that > would >> include jdom classes??? I am using eclipse. >> >> >> -----Original Message----- >> From: Rolf Lear [mailto:jdom at tuis.net] >> Sent: Monday, August 20, 2012 11:35 AM >> To: Craig Christophersen >> Cc: jdom-interest at jdom.org >> Subject: Re: [jdom-interest] jdom2 migration issue >> >> >> Hi Craig. >> >> There must be some other imports from the org.jdom package (as well >> as org.jdom2....). >> >> The error message you are getting would be impossible unless you have >> those imports. >> >> Something is wrong in your imports.... and your build path must have > some >> old JDOM classes from places other than just the old JDOM jar. >> >> Finally, it is normal in GUI-type development tools, (eclipse, IntelliJ, >> etc) to exclude the package on field names.... i.e. the line: >> >> protected org.jdom2.Document document; >> >> would not normally be created by Eclipse/IntelliJ unless your class >> was already using the org.jdom.Document version somewhere. You should > probably >> replace the line with: >> >> protected Document document; >> >> and ensure that you can import Document from org.jdom2 with >> >> import org.jdom2.Document; >> >> Bottom line is that you still have old JDOM classes in your build >> path, and the copde you have shown us us using *both* Document >> versions (org.jdom, as well as org.jdom2). >> >> Rolf >> >> >> >> >> >> On Mon, 20 Aug 2012 09:58:15 -0600, "Craig Christophersen" >> wrote: >>> Hello; >>> >>> I have been trying to migrate to Jdom2 in an application. I have >> followed >>> the migration guide but get a type mismatch error. >>> >>> Snippit below: >>> >>> protected org.jdom2.Document document; >>> >>> >>> >>> private String str = null; >>> >>> private String dmString = ""; >>> >>> String f = "f"; >>> >>> String t = "t"; >>> >>> protected DocType dt; >>> >>> /** >>> >>> * Read the specified File and parse it to create a JDOM tree >>> >>> **/ >>> >>> public ReadDmFile(File dmFile)// throws IOException, >>> JDOMException >>> { >>> >>> { >>> >>> System.out.println("File in ReadDm X: " + dmFile); >>> >>> >>> >>> try { >>> >>> SAXBuilder builder = >>> >>> new SAXBuilder(); //"org.apache.xerces.parsers.SAXParser" >>> >>> >>> >>> // Parse the specified file and convert it to a JDOM >>> document >>> >>> builder.setIgnoringElementContentWhitespace(true); >>> >>> document = builder.build(dmFile); >>> >>> >>> >>> >>> >>> >>> >>> On last line I get "Type mismatch: cannot convert from >> org.jdom2.Document >>> to >>> org.jdom.Document" >>> >>> The old jdom jar is removed from this project. >>> >>> Any help would be appreciated. >>> >>> >>> >>> Thanks, >>> >>> >>> >>> >>> >>> Craig Christophersen >>> >>> Software Developer >>> >>> Synesis7 >>> >>> craigch at synesis7.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jdom at tuis.net Mon Aug 20 13:31:33 2012 From: jdom at tuis.net (Rolf Lear) Date: Mon, 20 Aug 2012 16:31:33 -0400 Subject: [jdom-interest] jdom2 migration issue Message-ID: Hi Chris. Don't be too hard on yourself. It is an eclipse problem, and many people have wasted hours on this type of problem. I should update the migration page. Pleased it is now working, and I hope it does not sour your JDOM2 experience. Rolf Craig Christophersen wrote:Took two cleans to get it all clean. Changed back: final org.jdom2.Document mydoc = builder.build(dmFile); ??? document = mydoc; to: document = builder.build(dmFile); in that one class. All now compiles. Thank you much for your help??I guess this was more of an eclipse and developer not cleaning his project enough issue. ? I look forward to running this application now, and learning more about the enhancements in jdom2. Thank you again, Craig ??? ? From: Rolf Lear [mailto:jdom at tuis.net] Sent: Monday, August 20, 2012 2:06 PM To: craigch at synesis7.com Cc: jdom-interest at jdom.org Subject: RE: [jdom-interest] jdom2 migration issue ? In eclipse do a 'clean' on your project... ? Perhaps there are some 'vestiges' of a previous eclipse build. ? Rolf ? Craig Christophersen wrote: This is very peculiar.? That line now compiles. But further down in the class is another method using? "document" that will not(with the same type mismatch error). The line " Element root = document.getRootElement();? errors. Method: ? public String getWPNum() throws JDOMException { ??????? String wpNum = ""; ??????????? Element root = document.getRootElement(); ??????????? Element idstatus = (Element)root.getChild("idstatus"); ??????????? Element status = (Element)idstatus.getChild("status"); ??????????? Element remarks = (Element)status.getChild("remarks"); ??????????? wpNum = remarks.getText(); ??????????? if(wpNum.equals("")) { ?????????????? wpNum = "0"; ??????????? } ??????????? System.out.println("WPNum in Read DM: " + wpNum); ??????????????????? ??????? return wpNum; ??? } -----Original Message----- From: Rolf Lear [mailto:jdom at tuis.net] Sent: Monday, August 20, 2012 1:02 PM To: Craig Christophersen Cc: Jdom interest Subject: RE: [jdom-interest] jdom2 migration issue Right, then the next thing to do is to worry about the protected variable 'document'. In your code you have protected org.jdom2.Document document; I had assumed that this was the same variable as the one in the line: ??? document = builder.build(dmFile); But, now I am not so sure.... perhaps in this case the document in the build line is some other document variable with the same name from a super class or something. So, what happens if you replace the build line: ??? document = builder.build(dmFile); with: ??? final org.jdom2.Document mydoc = builder.build(dmFile); ??? document = mydoc; Rolf On Mon, 20 Aug 2012 12:51:33 -0600, "Craig Christophersen" wrote: > In the open type window it does show another project in eclipse with > "org.jdom.Document".? But it is another project that I will migrate > also once I get it working in this project.? The other project is not referenced > by the current project. > > There are 8 classes in the project that use jdom.? Below is a typical > import: > > import java.io.*; > import java.util.*; > import java.util.regex.Pattern; > > import org.jdom2.*; > import org.jdom2.filter.ElementFilter; import > org.jdom2.input.SAXBuilder; > > And another class imports: > > import java.io.*; > import java.util.*; > import java.io.File.*; > import java.io.IOException; > import java.util.concurrent.ConcurrentLinkedQueue; > > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; > > import org.jaxen.JaxenException; > > import org.jdom2.output.*; > import org.jdom2.*; > import org.jdom2.filter.ElementFilter; import > org.jdom2.filter.ContentFilter; import org.jdom2.input.*; import > org.jdom2.xpath.*; > > -----Original Message----- > From: Rolf Lear [mailto:jdom at tuis.net] > Sent: Monday, August 20, 2012 12:25 PM > To: Craig Christophersen; Jdom interest > Subject: RE: [jdom-interest] jdom2 migration issue > > > In eclipse, edit your file, then type shift-ctrl-T Then type > org.jdom.Document > > In the box below, you have all the locations of jdom 1.x Documents. > > As a double-check, can you copy/paste the entire import section in > your class.... I am convinced there must be an import from org.jdom.* > or something. > > P.S. when you reply, do a reply-all, and I will get your answer > faster..... > > Rolf > > > On Mon, 20 Aug 2012 12:18:29 -0600, "Craig Christophersen" > wrote: >> Hello Rolf; Thank you for your reply.? I have again looked thru stuff > and >> found no old jdom.? Are there known jars(I use several apache) that > would >> include jdom classes???? I am using eclipse. >> >> >> -----Original Message----- >> From: Rolf Lear [mailto:jdom at tuis.net] >> Sent: Monday, August 20, 2012 11:35 AM >> To: Craig Christophersen >> Cc: jdom-interest at jdom.org >> Subject: Re: [jdom-interest] jdom2 migration issue >> >> >> Hi Craig. >> >> There must be some other imports from the org.jdom package (as well >> as org.jdom2....). >> >> The error message you are getting would be impossible unless you have >> those imports. >> >> Something is wrong in your imports.... and your build path must have > some >> old JDOM classes from places other than just the old JDOM jar. >> >> Finally, it is normal in GUI-type development tools, (eclipse, IntelliJ, >> etc) to exclude the package on field names.... i.e. the line: >> >>???? protected org.jdom2.Document document; >> >> would not normally be created by Eclipse/IntelliJ unless your class >> was already using the org.jdom.Document version somewhere. You should > probably >> replace the line with: >> >>???? protected Document document; >> >> and ensure that you can import Document from org.jdom2 with >> >>???? import org.jdom2.Document; >> >> Bottom line is that you still have old JDOM classes in your build >> path, and the copde you have shown us us using *both* Document >> versions (org.jdom, as well as org.jdom2). >> >> Rolf >> >> >> >> >> >> On Mon, 20 Aug 2012 09:58:15 -0600, "Craig Christophersen" >> wrote: >>> Hello; >>> >>> I have been trying to migrate to Jdom2 in an application.? I have >> followed >>> the migration guide but get a type mismatch error. >>> >>> Snippit below: >>> >>>??? protected org.jdom2.Document document; >>> >>>? >>> >>>???? private String str = null; >>> >>>???? private String dmString = ""; >>> >>>???? String f = "f"; >>> >>>???? String t = "t"; >>> >>>???? protected DocType dt; >>> >>>???? /** >>> >>>????? * Read the specified File and parse it to create a JDOM tree >>> >>>????? **/ >>> >>>???? public ReadDmFile(File dmFile)// throws IOException, >>> JDOMException >>> { >>> >>>???? { >>> >>>???????? System.out.println("File in ReadDm X: " + dmFile); >>> >>>??????? >>> >>>???????? try { >>> >>>???????? SAXBuilder builder = >>> >>>???????????? new SAXBuilder(); //"org.apache.xerces.parsers.SAXParser" >>> >>>?????? >>> >>>???????? // Parse the specified file and convert it to a JDOM >>> document >>> >>>???????? builder.setIgnoringElementContentWhitespace(true); >>> >>>???????? document = builder.build(dmFile); >>> >>>? >>> >>>? >>> >>>? >>> >>> On last line I get "Type mismatch: cannot convert from >> org.jdom2.Document >>> to >>> org.jdom.Document" >>> >>> The old jdom jar is removed from this project. >>> >>> Any help would be appreciated. >>> >>>? >>> >>> Thanks, >>> >>>? >>> >>>? >>> >>> Craig Christophersen >>> >>> Software Developer >>> >>> Synesis7 >>> >>> craigch at synesis7.com -------------- next part -------------- An HTML attachment was scrubbed... URL: