• Post Reply Bookmark Topic Watch Topic
  • New Topic

static instance are being serialized?? Why??  RSS feed

 
Aadi Dasu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 3 classes as mentioned below(can copy and run them..I tried it)
I am getting
java.io.NotSerializableException: FastDateFormat$TwoDigitNumberField
when I try to serialize an instance of Employee.

TwoDigitNumberField is a Inner class
and an instance of it
static final TwoDigitNumberField INSTANCE = new TwoDigitNumberField();
is created and stored in transient array []mrules.
This array is marked as transient. So I shouldn't be getting the exception??

Can someone explain why the Static inner class instances are getting serialized???

thanks
Aadi



===================================================
import java.text.Format;

class Employee implements java.io.Serializable {

Format format;
}

====================================================


import java.io.*;
import java.text.DateFormat;
import java.util.Locale;

public class HeadQuarterEmpProcessor {

public static void main(String[] args) {
Employee emp = new Employee() ;
emp.format = FastDateFormat.getDateInstance(DateFormat.MONTH_FIELD,Locale.FRANCE);
FileOutputStream fOut=null;
ObjectOutputStream oOut=null;

try{
fOut= new FileOutputStream("c:\\NewEmployee.ser");
oOut = new ObjectOutputStream(fOut);
oOut.writeObject(emp); //serializing employee
System.out.println(
"An employee is serialized into c:\\NewEmployee.ser");
}catch(IOException e){
e.printStackTrace();
}finally{
try {
oOut.flush();
oOut.close();
fOut.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
===========================================
The 3rd class is here.
http://www.docjar.com/download.jsp?q=org.apache.commons.lang.time.FastDateFormat
 
Aadi Dasu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Ignore this POST.
The mRules was not transient in compiled source.
Code MISMATCH.
-Aadi.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!