java.io.InvalidClassException: org.jfree.data.time.Second;

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
annac
Posts: 24
Joined: Mon Oct 01, 2007 7:56 pm
Location: Canada

java.io.InvalidClassException: org.jfree.data.time.Second;

Post by annac » Tue Oct 23, 2007 5:31 pm

Hi,

I have embedded a jfreechart applet in an html page. The applet is passed a serialized object from a servlet (connected to our database) which contains a TimeSeries. I am getting the following error:

java.io.InvalidClassException: org.jfree.data.time.Second; incompatible types for field second
at java.io.ObjectStreamClass.matchFields(Unknown Source)
at java.io.ObjectStreamClass.getReflector(Unknown Source)
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.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.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 ChartApplet.getInfo(ChartApplet.java:441)
at ChartApplet.init(ChartApplet.java:108)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

I realize this is probably not a jfreechart issue but I am hoping someone has dealt with this error before...

The html <applet> tag has the following archive attribute:
archive="jfreechart-1.0.6.jar, jcommon-1.0.10.jar, jfreechart-1.0.6-experimental.jar, graphinfo.jar"

The servlet previously had access to later versions of the jfreechart and jcommon jars and I thought that maybe that was the problem but I have switched them for the newer versions and the problem is still not solved.

The only code that uses the Second class is the following: (using Hibernate)

Code: Select all

	private XYDataset createDataset(int deviceId, int sensorId, HashMap<String, Double> minMaxValues,
			String sensorTypeName, Date startDate, Date endDate, int graphWidth) throws Exception {
				
		TimeSeries ts1 = new TimeSeries(sensorTypeName);
		
		List<ISampleScaledSimpleState> readings = getData(deviceId, sensorId, startDate, endDate, graphWidth);

		for (ISampleScaledSimpleState iSampleScaledSimpleState : readings) {
			
			Date theDate = iSampleScaledSimpleState.getDateFrom();
			
			ts1.addOrUpdate(new Second(theDate), iSampleScaledSimpleState.getCorrectedValue());
			
			// s1.add(iSampleScaledSimpleState.getDateFrom().getTime(), iSampleScaledSimpleState.getCorrectedValue());
			// USE ONLY THE SECOND FROM THE TIMESTAMP, NOT THE MILLISECOND
			// OK FOR PLOTTING
			// s1.add(new Date(iSampleScaledSimpleState.getDateFrom().getTime()),
			// iSampleScaledSimpleState.getCorrectedValue());

			if (minMaxValues.get("max") == null || minMaxValues.get("min") == null) {
				minMaxValues.put("max", iSampleScaledSimpleState.getCorrectedValue());
				minMaxValues.put("min", iSampleScaledSimpleState.getCorrectedValue());
			}
			if (iSampleScaledSimpleState.getCorrectedValue() > minMaxValues.get("max")) {
				minMaxValues.put("max", iSampleScaledSimpleState.getCorrectedValue());
			}
			if (iSampleScaledSimpleState.getCorrectedValue() < minMaxValues.get("min")) {
				minMaxValues.put("min", iSampleScaledSimpleState.getCorrectedValue());
			}

		}
		readings = null;
		TimeSeriesCollection dataset = new TimeSeriesCollection();
		dataset.addSeries(ts1);
		return dataset;
	}
Any help would be appreciated! This really has me stuck...[/code]

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Oct 24, 2007 10:45 pm

It sounds like you have a serialized instance from a recent version of JFreeChart being deserialized on an older verison of JFreeChart. In theory it should work, but then I did make some changes to the RegularTimePeriod classes in recent releases, and its very possible that I broke serialization for older versions. Sorry.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

annac
Posts: 24
Joined: Mon Oct 01, 2007 7:56 pm
Location: Canada

Post by annac » Wed Oct 24, 2007 10:53 pm

I was careful to reference the same version of the jfreechart jars (jfreechart 1.0.6, jcommon 1.0.10) from the applet as the ones available to the servlet (Originally the servlet had access to older versions) but this didn't help the problem. We have come up with a workaround but it's fairly messy (involves passing the data as the int values of second, minute, hour, day, etc. instead of passing Second objects) and fixing the issue with the serialization of Second would be preferred...

Locked