You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Jed Wesley-Smith (JIRA)" <ji...@apache.org> on 2006/12/11 08:48:23 UTC
[jira] Commented: (LUCENE-681) org.apache.lucene.document.Field is
Serializable but doesn't have default constructor
[ http://issues.apache.org/jira/browse/LUCENE-681?page=comments#action_12457253 ]
Jed Wesley-Smith commented on LUCENE-681:
-----------------------------------------
worksforme
public class SerializationTest
{
public static void main(String[] args) throws Exception
{
Field field = new Field("name", "value", Field.Store.YES, Field.Index.TOKENIZED);
System.out.println(field);
final Object field2 = new SerializationTest().serialize(field);
System.out.println(field2);
System.out.println(field == field2);
}
Object serialize(Object input) throws IOException, ClassNotFoundException
{
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
ObjectOutputStream outObjects = new ObjectOutputStream(outBytes);
outObjects.writeObject(input);
ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
ObjectInputStream inObjects = new ObjectInputStream(inBytes);
return inObjects.readObject();
}
}
Its a final class dude, what does it need a default constructor for?
Consider closing.
> org.apache.lucene.document.Field is Serializable but doesn't have default constructor
> -------------------------------------------------------------------------------------
>
> Key: LUCENE-681
> URL: http://issues.apache.org/jira/browse/LUCENE-681
> Project: Lucene - Java
> Issue Type: Bug
> Components: Other
> Affects Versions: 1.9, 2.0.0, 2.1, 2.0.1
> Environment: doesn't depend on environment
> Reporter: Elijah Epifanov
> Priority: Critical
>
> when I try to pass Document via network or do anyhing involving serialization/deserialization I will get an exception.
> the following patch should help (Field.java):
> public Field () {
> }
> private void writeObject (java.io.ObjectOutputStream out)
> throws IOException {
> out.defaultWriteObject ();
> }
> private void readObject (java.io.ObjectInputStream in)
> throws IOException, ClassNotFoundException {
> in.defaultReadObject ();
> if (name == null) {
> throw new NullPointerException ("name cannot be null");
> }
> this.name = name.intern (); // field names are interned
> }
> Maybe other classes do not conform to Serialization requirements too...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org