• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A strange sequence hua java Trouble

 
zhang jin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code Applet program

This is a method of post-processing program

I will JasperPrint ObjectOutputStream stream serialized to go and then use ObjectInputStream Applet want to deserialize objects they found out JasperPrint serialVersionUID inconsistent versions, confirm that the same object is a class file JasperPrint inside net.sf.jasperreports.engine.JasperPrint ! jre javaee inside the jar and the jar inside the package is the same! but why not deserialize read out JasperPrint object has been suggested serialVersionUID wrong version ... is the sequence of time if other classes of such references, then the other serialVersionUID version of the class also needs to be consistent? I guess it was only for this reason it! feel so strange?
The following error message may be determined based on the error can be determined JasperPrint is inconsistent versions of this class, but I like this version is the same! Jdk environment is not at issue in how the environment is problematic Applet!
java.io.InvalidClassException: javax.swing.JComponent; local class incompatible: stream classdesc serialVersionUID = -5074484439485650315, local class serialVersionUID = 3742318830738515599
at java.io.ObjectStreamClass.initNonProxy (Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc (Unknown Source)
at java.io.ObjectInputStream.readClassDesc (Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc (Unknown Source)
at java.io.ObjectInputStream.readClassDesc (Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc (Unknown Source)
at java.io.ObjectInputStream.readClassDesc (Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc (Unknown Source)
at java.io.ObjectInputStream.readClassDesc (Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject (Unknown Source)
at java.io.ObjectInputStream.readObject0 (Unknown Source)
at java.io.ObjectInputStream.defaultReadFields (Unknown Source)
at java.io.ObjectInputStream.readSerialData (Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject (Unknown Source)
at java.io.ObjectInputStream.readObject0 (Unknown Source)
at java.io.ObjectInputStream.defaultReadFields (Unknown Source)
at java.io.ObjectInputStream.defaultReadObject (Unknown Source)
at net.sf.jasperreports.engine.fill.JRTemplatePrintImage.readObject (JRTemplatePrintImage.java:492)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source)
at java.lang.reflect.Method.invoke (Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject (Unknown Source)
at java.io.ObjectInputStream.readSerialData (Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject (Unknown Source)
at java.io.ObjectInputStream.readObject0 (Unknown Source)
at java.io.ObjectInputStream.readObject (Unknown Source)
at java.util.ArrayList.readObject (Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source)
at java.lang.reflect.Method.invoke (Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject (Unknown Source)
at java.io.ObjectInputStream.readSerialData (Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject (Unknown Source)
at java.io.ObjectInputStream.readObject0 (Unknown Source)
at java.io.ObjectInputStream.defaultReadFields (Unknown Source)
at java.io.ObjectInputStream.readSerialData (Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject (Unknown Source)
at java.io.ObjectInputStream.readObject0 (Unknown Source)
at java.io.ObjectInputStream.defaultReadFields (Unknown Source)
at java.io.ObjectInputStream.readSerialData (Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject (Unknown Source)
at java.io.ObjectInputStream.readObject0 (Unknown Source)
at java.io.ObjectInputStream.readObject (Unknown Source)
at java.util.ArrayList.readObject (Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source)
at java.lang.reflect.Method.invoke (Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject (Unknown Source)
at java.io.ObjectInputStream.readSerialData (Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject (Unknown Source)
at java.io.ObjectInputStream.readObject0 (Unknown Source)
at java.io.ObjectInputStream.defaultReadFields (Unknown Source)
at java.io.ObjectInputStream.readSerialData (Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject (Unknown Source)
at java.io.ObjectInputStream.readObject0 (Unknown Source)
at java.io.ObjectInputStream.defaultReadFields (Unknown Source)
at java.io.ObjectInputStream.defaultReadObject (Unknown Source)
at net.sf.jasperreports.engine.JasperPrint.readObject (JasperPrint.java:849)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source)
at java.lang.reflect.Method.invoke (Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject (Unknown Source)
at java.io.ObjectInputStream.readSerialData (Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject (Unknown Source)
at java.io.ObjectInputStream.readObject0 (Unknown Source)
at java.io.ObjectInputStream.readObject (Unknown Source)
at arg.x.applet.PublicModel.printPdf (PublicModel.java:20)
at arg.x.applet.PublicModel.init (PublicModel.java:33)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init (Unknown Source)
at sun.plugin2.applet.Plugin2Manager $ AppletExecutionRunnable.run (Unknown Source)
at java.lang.Thread.run (Unknown Source)
 
L Foster
Ranch Hand
Posts: 185
10
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Zhang Jin,
Hello.

I think the problem you are showing us is the serial version UID mismatch. Very likely you have different versions of classes on one side versus the other. This is almost always how these problems happen. The short response is: build, and deploy the same classes everywhere. If you want more, read on.

When you use Java Object serialization (which uses the combination of ObjectOutputStream / ObjectInputStream classes), there is a serialVersionUID created for a Serializable class when it is compiled. There is some algorithm (which I have never bothered to learn) that calculates that UID. It takes things into account like the method signatures.

The serialVersionUID is supposed to act as a safety catch to avoid mixing mismatched class definitions and avoid other, worse problems later.

There are code-modification rules about when the UID changes. I could be wrong about this, but I tend to assume that if you compile the class on different JDKs, you can get a different UID. So, the best way to assure that you won't get different UIDs, is to build your application (applet front end and backend) such that the classes used by the applet are exactly the same classes used on the server. To be very specific: I mean don't assume because the source code is the same that you can compile separately. IMHO, it is not good code practice to distribute source code between client and server, anyway.

There is also something folks do sometimes, to specifically set the serialVersionUID so it never changes. I have seen this done for cases where people are making a lot of changes to classes and they do not want to be bothered by this problem (in development, especially, they want to compile stuff on both sides, and not redeploy, etc.). This is not necessarily a best practice, because it bypasses this safety mechanism.

Here's more information on serialization.

http://docs.oracle.com/javase/tutorial/jndi/objects/serial.html

You may also wish to be aware, that there are projects out there which have sprung up at least partly owing to this problem. Sometimes redistributing classes (let alone source code) is problematic. For example, when an API has been made public, and you may over time just want to add hooks to its classes without changing the behavior of existing methods, but you cannot distribute a new version of some client. You can look at Protobuf for example.

Hope it helps.
 
Tony Docherty
Bartender
Posts: 3054
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to the Ranch.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic