Error serializing script library

I don’t think I have that many scripts in my project, but I’m getting a message saying the encoded string is too long.

[code]com.inductiveautomation.ignition.common.xmlserialization.SerializationException: IOException during serialization.
at com.inductiveautomation.ignition.common.xmlserialization.serialization.XMLSerializer.serialize(XMLSerializer.java:430)
at com.inductiveautomation.ignition.common.xmlserialization.serialization.XMLSerializer.serializeBinary(XMLSerializer.java:406)
at com.inductiveautomation.ignition.common.xmlserialization.serialization.XMLSerializer.serializeBinary(XMLSerializer.java:399)
at com.inductiveautomation.ignition.designer.scripteditor.ModuleEditor.serialize(ModuleEditor.java:415)
at com.inductiveautomation.ignition.designer.scripteditor.ModuleEditor.doApply(ModuleEditor.java:394)
at com.inductiveautomation.ignition.designer.scripteditor.ModuleEditor$3.actionPerformed(ModuleEditor.java:453)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.io.UTFDataFormatException: encoded string too long: 70506 bytes
at java.io.DataOutputStream.writeUTF(Unknown Source)
at java.io.DataOutputStream.writeUTF(Unknown Source)
at com.inductiveautomation.ignition.common.xmlserialization.serialization.BinaryWriter.writeStringTable(BinaryWriter.java:87)
at com.inductiveautomation.ignition.common.xmlserialization.serialization.BinaryWriter.writeElement(BinaryWriter.java:63)
at com.inductiveautomation.ignition.common.xmlserialization.serialization.XMLSerializer.serialize(XMLSerializer.java:428)
… 42 more

Ignition v7.3.1 (b496)
Java: Sun Microsystems Inc. 1.6.0_26
[/code]

The jokester at Sun who originally wrote DataOutputStream thought this was a good idea:

if (utflen > 65535) throw new UTFDataFormatException( "encoded string too long: " + utflen + " bytes");

We’ve recently become aware of this issue and are working on a fix for it. In the mean-time, you either have too many scripts or one script in particular is too long. I’ll ask another developer when he gets here and let you know if there’s any work around right now…

I looked at the code, and while it is technically correct this could have been completely avoided with a 4 byte header instead of a 2 byte header. Could you just wrap the call to DataOutputStream or is it called from within your xml serializer itself?

s = "some string that i want to run through DataOutputStream, and might be bigger than 65535 bytes"

DataOutputStream outputStream = new DataOutputStream(baStream)
if (s == null) {
	outputStream.writeByte(0)
}
else if (s.length() >= 65535) {
	byte[] b = s.getBytes("utf-8");
	outputStream.writeInt(b.length);
	outputStream.write(b);
}
else {
	outputStream.writeUTF(s);
} 

byte[] result = baStream.toByteArray() // can do whatever with this now.

This has already been fixed. It’ll be in the 7.3.2 release. If you’d like, you can get it early by downloading the 7.3.2 beta.

Thanks Carl. I’ve whittled down the scripting so it works on some legacy installs, but I guess I’ll be able to put all the comments back in now. :mrgreen: