ClassCastException: SimpleTimeZone to ZoneInfo in readObject

Hello
I have a java application running on weblogic.
Java version - 1.6.0_17-b04
And a client application written in Java as well (same version).
There are objects with GregorianCalendar which are transfered from server to client via RMI.
I occasionally get the following error:
Caused by: java.lang.ClassCastException: java.util.SimpleTimeZone cannot be cast to sun.util.calendar.ZoneInfo
at java.util.Calendar$1.run(Unknown Source)
at java.util.Calendar$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.Calendar.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor23.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.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.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.GeneratedMethodAccessor28.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
I see that the readObject of Calendar code is:
ZoneInfo zi = null;
     try {
         zi = AccessController.doPrivileged(
              new PrivilegedExceptionAction<ZoneInfo>() {
               public ZoneInfo run() throws Exception {
                   return (ZoneInfo) input.readObject();
              CalendarAccessControlContext.INSTANCE);
     } catch (PrivilegedActionException pae) {
         Exception e = pae.getException();
         if (!(e instanceof OptionalDataException)) {
          if (e instanceof RuntimeException) {
              throw (RuntimeException) e;
          } else if (e instanceof IOException) {
              throw (IOException) e;
          } else if (e instanceof ClassNotFoundException) {
              throw (ClassNotFoundException) e;
          throw new RuntimeException(e);
     if (zi != null) {
         zone = zi;
     // If the deserialized object has a SimpleTimeZone, try to
     // replace it with a ZoneInfo equivalent (as of 1.4) in order
     // to be compatible with the SimpleTimeZone-based
     // implementation as much as possible.
     if (zone instanceof SimpleTimeZone) {
         String id = zone.getID();
         TimeZone tz = TimeZone.getTimeZone(id);
         if (tz != null && tz.hasSameRules(zone) && tz.getID().equals(id)) {
          zone = tz;
     }There is casting to ZoneInfo no matter what's the class is actually instance of.
In my case, the calendar sometimes contains SimpleTimeZone and not ZoneInfo which causes for the ClassCastException.
I also find that there are occasions where the zone variable holds SimpleTimeZone (gets to the line "if (zone instanceof SimpleTimeZone)" and equals true) but doesn't fail in "return (ZoneInfo) input.readObject();".
Any idea?

Yeah, they changed the default timezone's type between JDKs (or something along those lines) and it's breaking up some things.
Some more info [here.|http://www.coderanch.com/t/496765/java/java/ClassCastException-during-SimpleTimeZone-ZoneInfo-conversion]

Similar Messages

  • Having Trouble Reading in an Object

    im trying to read in a JTabbedPane (called AZTabs) using this method:
    public void readContact(){
            in = null;
            try{
                in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("files/contacts")));
                for(index3 = 0; index3 < AZTabs.getTabCount(); index3++){
                    AZTabs = (JTabbedPane)in.readObject();
            }catch(ClassNotFoundException e){
                System.out.println("Caught ClassNotFoundException " + e.getMessage());
            }catch(IOException e){
                System.err.println("Caught IOException " + e.getMessage());
            }finally{
                if(in != null){
                    try{
                        in.close();
                    }catch(IOException e){
                        System.err.println("Caught IOException " + e.getMessage());
        }whenever i run my app it give me this exception: "Exception in thread "main" java.lang.ClassCastException: javax.swing.JPanel cannot be cast to javax.swing.JTabbedPane". any1 know what i can do to solve this problem?
    thnx guys

    The data you are trying to read is a serialized JPanel.
    When it is read in, the object it produces is a JPanel.
    You cannot treat a JPanel as a JTabbedPane because it is not a JTabbedPane, it is a JPanel.
    I don't see how you're getting confused.
    JTabbedPane p = (JTabbedPane) in.readObject();
    // throws a ClassCastException at runtime because the readObject() method is returning a JPanel
    JTabbedPane p = (JPanel) in.readObject();
    // produces a compiler error because you cannot assign a JPanel reference to a JTabbedPane reference
    JPanel p = (JPanel) in.readObject();
    // should work just fine and dandy

  • Casting timezone class object to Simpletimezone class object

    When i try to cast timezone class object to a simpletimezone object it throws "java.lang.classcastexception" when i use J2re 1.4.2_06 while in J2re1.3 it works fine .
    I am unable to understand this , can anybody help me out in this regard.
    thanks
    Lokesh

    I agree with all
    but try this out
    SimpleTimeZone stz = (SimpleTimeZone)
    ne) TimeZone.getTimeZone(id);Nothing in the specification says that
    TimeZone.getTimeZone(id) returns an object that is a
    SimpleTimeZone only that it is a TimeZone. It might
    happen to also be a SimpleTimeZone but nothing in the
    specifications says that it is.
    Above statement throws classcast exception in
    in jre1.4.2 but not in Jre1.3 and lower versions
    ........ remember TimeZone is base class and
    SimpleTimeZone is sub class.If this is correct then in 1.3 it just happens to
    return SimpleTimeZone object but nothing in the spec
    says you can rely on this. You are relying on an
    undocumented feature! Always a bad idea.
    So wht has changed in the 2 runtimeenvironments.
    Retorical?Hi,
    sabre150 thanx a lot , u are right in earlier versions TimeZone.getTimeZone(id) was returning SimpleTimeZone object but in J2re 1.4.2 it returns sun.util.calendar.ZoneInfo object and hence the class cast exception was happening.
    AND BELLYRIPPER , u were theoretically right , i was asking something that was happening in practical , so u better try out things and then come up with reasoning rather than just repeating theoretical things and expecting others to accept them blindly.
    Anyway thanx a lot for the help.

  • BC4J ServerModul in JBoss 3.2.3 throws a ClassCastException in SwingClient

    Hi Everyone,
    in the last days i start crying very often, because i think i make a simple mistake with a hugh result -> nothing works ;(
    Whats going wrong?
    I deployed my BC4J ApplicationModule in JBoss, without any problems.
    But when i try to access my ApplicationModule from a SwingClient i get headache. I did it like the HowTos explained. okay they are a bit out of date but it seems
    that there are no points, where i could do something really wrong.
    So i copied all libs and created a sample client explained in: http://otn.oracle.com/products/jdev/howtos/appservers/deploy_bc4j_to_jboss.html
    And here is the problem:
    The first problem i found is, that i can not lookup the
    ApplicationModul via: ctx.lookup("de.orb.server.ServerModule")
    This always results in a exception saying that this JNDI Name is not bound... okay.. i changed it to the EJB Name provided by JBoss: ctx.lookup("ServerModuleBMBean") and the Bean is found. Everything is fine.
    When i try to access a ViewObject i got a reference which is looking fine, BUT doing operations on this reference always result in a very strange ClassCastException;
    oracle.jbo.common.JboExMsgCarrier: java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrappedPreparedStatement
         void oracle.jbo.common.PiggybackExceptionEntry.readObject(java.io.ObjectInputStream)
              PiggybackExceptionEntry.java:135
         java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[])
              native code
         boolean java.io.ObjectInputStream.invokeObjectReader(java.lang.Object)
              ObjectInputStream.java:2214
         int java.io.ObjectInputStream.inputObject(boolean)
              ObjectInputStream.java:1411
         java.lang.Object java.io.ObjectInputStream.readObject(boolean)
              ObjectInputStream.java:386
         java.lang.Object java.io.ObjectInputStream.readObject()
              ObjectInputStream.java:236
         void oracle.jbo.common.PiggybackInput.<init>(oracle.jbo.common.ObjectMarshaller, byte[])
              PiggybackInput.java:63
         void oracle.jbo.common.PiggybackInput.<init>(byte[])
              PiggybackInput.java:38
         void oracle.jbo.client.remote.ejb.RootApplicationModuleImpl.processRemoteJboException(oracle.jbo.common.remote.ejb.RemoteJboException)
              RootApplicationModuleImpl.java:2925
         oracle.svcmsg.ServiceMessage oracle.jbo.client.remote.ejb.RootApplicationModuleImpl.riExecuteQuery(int, boolean, oracle.svcmsg.ServiceMessage)
              RootApplicationModuleImpl.java:735
         oracle.svcmsg.ServiceMessage oracle.jbo.client.remote.ejb.EJBApplicationModuleImpl.riExecuteQuery(int, boolean, oracle.svcmsg.ServiceMessage)
              EJBApplicationModuleImpl.java:314
         void oracle.jbo.client.remote.ApplicationModuleImpl.executeQuery(int, boolean)
              ApplicationModuleImpl.java:5982
         void oracle.jbo.client.remote.RowSetImpl.executeQuery()
              RowSetImpl.java:950
         void oracle.jbo.client.remote.ViewUsageImpl.executeQuery()
              ViewUsageImpl.java:556
    other Operations like:
    System.err.println( vo.getApplicationModule().getName() );
    System.err.println( vo.getName() );
    System.err.println( vo.getFullName() );
    System.err.println( vo.getQuery() );
    System.err.println( ""+vo );
    are working fine....
    Please can anyone help me to solve this very strange problem. I need some advice, because i do not know what
    happen et al.
    I do not need to know how BC4J works with JSP Pages, i need to know how i can get it working with my SwingApplication and JBoss.
    Regards Mirko
    PS: Happy Easter!
    i am using:
    Jboss 3.2.3
    Oracle 8i Database
    JDeveloper 9.0.3.1035

    I passed through this problem by adding the following property to the hashtable used to create InitialContext
    env.put
    (oracle.jbo.common.PropertyConstants.PN_SQLBUILDERIMPL,
    oracle.jbo.common.PropertyConstants.SQL92);
    Context ctx = new InitialContext(env);
    Best regards,
    Eduardo.

  • ClassCastException in InvocableMap.ParallelAwareAggregator

    I am using InvocableMap.ParallelAwareAggregator to sort results set on cache server side. But I'm keep getting ClassCastException like below :
    2008-02-14 17:33:28.603 Oracle Coherence DC 3.3.1/389p1 <Info> (thread=main, member=n/a): Connected to 10.5.235.162:9096
    Exception in thread "main" com.tangosol.io.pof.PortableException (Remote: An exception occurred while processing a AggregateFilterRequest) (Wrapped: Failed request execution for DistributedService service on Member(Id=10, Timestamp=2008-02-14 17:21:38.86, Address=10.5.235.162:8089, MachineId=58530, Location=machine:docqa4,member:dvCache2)) java.lang.ClassCastException
    at com.docview.test.SortByServerAggregator$SortingParallelAggregator.sortByDate(SortByServerAggregator.java:188)
    at com.docview.test.SortByServerAggregator$SortingParallelAggregator.sortEntries(SortByServerAggregator.java:151)
    at com.docview.test.SortByServerAggregator$SortingParallelAggregator.aggregate(SortByServerAggregator.java:133)
    at com.tangosol.coherence.component.util.daemon.queueProcessor.service.DistributedCache.onAggregateFilterRequest(DistributedCache.CDB:74)
    at com.tangosol.coherence.component.util.daemon.queueProcessor.service.DistributedCache$AggregateFilterRequest.run(DistributedCache.CDB:1)
    at com.tangosol.coherence.component.util.DaemonPool$WrapperTask.run(DaemonPool.CDB:24)
    at com.tangosol.coherence.component.util.DaemonPool$Daemon.onNotify(DaemonPool.CDB:49)
    at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:35)
    at java.lang.Thread.run(Thread.java:534)
    Any ideas ? I can see the messages in cache server logs which indicate the sorting is done and size of sorted entries on each cache server instance. But if trying to print out each entry, I will get ClassCastException.
    Attached please see my codes as below :
    ==================================================
    import java.io.DataInput;
    import java.io.DataOutput;
    import java.io.IOException;
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Iterator;
    import java.util.NoSuchElementException;
    import java.util.Set;
    import java.util.List;
    import java.util.TreeSet;
    import java.util.HashSet;
    import java.util.ArrayList;
    import com.tangosol.io.ExternalizableLite;
    import com.tangosol.util.ExternalizableHelper;
    import com.tangosol.util.InvocableMap;
    import com.tangosol.util.ValueExtractor;
    import com.tangosol.util.InvocableMap.Entry;
    import com.tangosol.util.InvocableMap.EntryAggregator;
    import com.tangosol.util.InvocableMap.ParallelAwareAggregator;
    import com.tangosol.util.extractor.ReflectionExtractor;
    import com.docview.query.Cache_Query_Constants;
    import com.docview.util.SortUtils;
    import com.docview.cache.MultiTagPubSearchCacheKey;
    import com.docview.entity.MultiTagPubSearchCacheEntity;
    public class SortByServerAggregator implements ParallelAwareAggregator, ExternalizableLite {
         private String sortFlag;
         private String ascDescFlag;
         public SortByServerAggregator(String sortFlag, String ascDescFlag) {
              this.sortFlag = sortFlag;
              this.ascDescFlag = ascDescFlag;
         public SortByServerAggregator() {
              super();
         public Object aggregate(Set entries) {
              return new SortingParallelAggregator(sortFlag, ascDescFlag).aggregate(entries);
         public Object aggregateResults(Collection resultObjects) {
              return mergeMultipleResults(resultObjects);
         public EntryAggregator getParallelAggregator() {
              return new SortingParallelAggregator(sortFlag, ascDescFlag);
         public void readExternal(DataInput input) throws IOException {
              sortFlag = ExternalizableHelper.readSafeUTF(input);
              ascDescFlag = ExternalizableHelper.readSafeUTF(input);
         public void writeExternal(DataOutput output) throws IOException {
              ExternalizableHelper.writeSafeUTF(output, sortFlag);
              ExternalizableHelper.writeSafeUTF(output, ascDescFlag);
         private List mergeMultipleResults(Collection resultObjects) {
              ArrayList list = new ArrayList();
              Iterator iter = resultObjects.iterator();
              while (iter.hasNext()) {
                   ParallelResultObject result = (ParallelResultObject)iter.next();
                   list.addAll(result.generateResultList());
              return list;
         public static class ParallelResultObject implements ExternalizableLite {
              private MultiTagPubSearchCacheEntity[] entries;
              public ParallelResultObject() {}
              public ParallelResultObject(MultiTagPubSearchCacheEntity[] entries) {
                   this.entries = entries;
              public List generateResultList() {
                   ArrayList l = new ArrayList();
                   for(int i=0;i<entries.length;i++) {
                        l.add(entries);
                   return l;
              public void readExternal(DataInput input) throws IOException {
                   int numEntries = ExternalizableHelper.readInt(input);
                   if(numEntries >0) {
                        entries = new MultiTagPubSearchCacheEntity[numEntries];
                        for(int i=0;i<numEntries;i++) {
                             entries[i] = (MultiTagPubSearchCacheEntity)ExternalizableHelper.readObject(input);     
              public void writeExternal(DataOutput output) throws IOException {
                   int numEntries = entries.length;
                   if(numEntries >0) {
                        ExternalizableHelper.writeInt(output, numEntries);
                        for(int i=0;i<numEntries;i++) {
                             ExternalizableHelper.writeObject(output, entries[i]);     
         public static class SortingParallelAggregator implements ExternalizableLite, EntryAggregator {
              private String sortFlag;
              private String ascDescFlag;
              public SortingParallelAggregator() {
                   super();
              public SortingParallelAggregator(String sortFlag, String ascDescFlag) {
                   super();
                   this.sortFlag = sortFlag;
                   this.ascDescFlag = ascDescFlag;
              public Object aggregate(Set entries) {
                   return sortEntries(entries, sortFlag, ascDescFlag);
              public void readExternal(DataInput input) throws IOException {
                   sortFlag = ExternalizableHelper.readSafeUTF(input);
                   ascDescFlag = ExternalizableHelper.readSafeUTF(input);
              public void writeExternal(DataOutput output) throws IOException {
                   ExternalizableHelper.writeSafeUTF(output, sortFlag);
                   ExternalizableHelper.writeSafeUTF(output, ascDescFlag);
              private ParallelResultObject sortEntries(Set entries, String sortFlag, String ascDescFlag) {
                   ArrayList sortedList;
                   ArrayList arrayList = new ArrayList(entries);     
                   if ( sortFlag != null && !"".equals(sortFlag.trim()) ) {
         if ( Cache_Query_Constants.DATE_SORT_FLAG.equals(sortFlag.trim().toUpperCase()) ) {
                             sortedList = sortByDate(arrayList, ascDescFlag);
         } else {
         sortedList = arrayList;
         } else {
         sortedList = arrayList;
                   return new ParallelResultObject(convertListToArray(sortedList));
              private ArrayList sortByDate(ArrayList arrayList, String ascDescFlag) {
                   if("DESC".equals(ascDescFlag.trim().toUpperCase())) {
                        System.out.println("Start sort by DATE DESC");
                        Collections.sort(arrayList, new Comparator() {
                             public int compare(Object o1, Object o2) {
                                  int rc = 0;
                                  if((o1 instanceof MultiTagPubSearchCacheEntity) && (o2 instanceof MultiTagPubSearchCacheEntity))
                                       System.out.println("Sorting by MultiTagPubSearchCacheEntity ...");
                                       MultiTagPubSearchCacheEntity p1 = (MultiTagPubSearchCacheEntity) o1;
                                       MultiTagPubSearchCacheEntity p2 = (MultiTagPubSearchCacheEntity) o2;
                                       rc = p1.getPub_Date() - p2.getPub_Date();
                                       if ( rc == 0 ) {
                                            rc = p2.getTitle().compareTo(p1.getTitle());
                                  return rc;
                        Collections.reverse(arrayList);
                        System.out.println("Done sort by DATE DESC");
                   System.out.println("Size of sorted result : " + arrayList.size());
                   Iterator iter = arrayList.iterator();
                   while(iter.hasNext()) {
         MultiTagPubSearchCacheEntity e = (MultiTagPubSearchCacheEntity)iter.next();
         System.out.println("### Sorted Entries : " + e.toString());
                   return arrayList;
              private MultiTagPubSearchCacheEntity[] convertListToArray(ArrayList sortedList) {
                   MultiTagPubSearchCacheEntity[] entries = new MultiTagPubSearchCacheEntity[sortedList.size()];
                   Iterator iter = sortedList.iterator();
                   int idx = 0;
                   while(iter.hasNext()) {
                        entries[idx] = (MultiTagPubSearchCacheEntity)iter.next();     
                        idx++;
                   return entries;
    ==================================================
    Thanks,
    Bing

    Hi, Gene
    I'm getting another ClassCastException during the client call as below :
    public class SortByServerFactory
            // sortFlag
            public static MultiTagPubSearchCacheEntity[] filterAndSortByServer(String cacheName, String sortFlag, String ascDescFlag, Filter filter)
                    InvocableMap cache = CacheFactory.getCache(cacheName);
                    return (MultiTagPubSearchCacheEntity[])cache.aggregate(filter, new SortByServerAggregator(sortFlag, ascDescFlag));
    }2008-02-15 15:11:41.850 Oracle Coherence DC 3.3.1/389p1 <Info> (thread=main, member=n/a): Connected to 10.56.32.91:9098
    Exception in thread "main" java.lang.ClassCastException
    at com.docview.test.SortByServerFactory.filterAndSortByServer(SortByServerFactory.java:16)
    at com.docview.test.TestRegSectorAnalystCacheQueryInvocationSVC.main(TestRegSectorAnalystCacheQueryInvocationSVC.java:83)
    Attached please find my updated "SortByServerAggregator" class also :
    The method "aggregateResults(Collection resultObjects)" within SortByServerAggregator class will return "MultiTagPubSearchCacheEntity[]"
    Would you please help me to point out where is problem ?
    Maybe I'm still not fully understand how ParallelAwareAggregator works, and what should be done for aggregate(Set entries), aggregateResults(Collection resultObjects) and getParallelAggregator() .
    Many thanks for your help.
    Bing
    =========================================================
    public class SortByServerAggregator implements ParallelAwareAggregator, ExternalizableLite {
         private String sortFlag;
         private String ascDescFlag;
         public SortByServerAggregator(String sortFlag, String ascDescFlag) {
              this.sortFlag = sortFlag;
              this.ascDescFlag = ascDescFlag;
         public SortByServerAggregator() {
              super();
         public Object aggregate(Set entries) {
              return new SortingParallelAggregator(sortFlag, ascDescFlag).aggregate(entries);
         public Object aggregateResults(Collection resultObjects) {
              return mergeMultipleResults(resultObjects);
         public EntryAggregator getParallelAggregator() {
              return new SortingParallelAggregator(sortFlag, ascDescFlag);
         public void readExternal(DataInput input) throws IOException {
              sortFlag = ExternalizableHelper.readSafeUTF(input);
              ascDescFlag = ExternalizableHelper.readSafeUTF(input);
         public void writeExternal(DataOutput output) throws IOException {
              ExternalizableHelper.writeSafeUTF(output, sortFlag);
              ExternalizableHelper.writeSafeUTF(output, ascDescFlag);
         private MultiTagPubSearchCacheEntity[] mergeMultipleResults(Collection resultObjects) {
              HashSet tmpSet = new HashSet();
              Iterator iter = resultObjects.iterator();
              while (iter.hasNext()) {
                   ParallelResultObject result = (ParallelResultObject)iter.next();
                   int numEntries = result.getNumEntries();
                   if(numEntries > 0) {
                        MultiTagPubSearchCacheEntity[] entries = result.getEntries();
                        for(int i=0;i<numEntries;i++) {
                             tmpSet.add(entries);     
              return toEntityArray(tmpSet);
         private MultiTagPubSearchCacheEntity[] toEntityArray(HashSet s) {
              MultiTagPubSearchCacheEntity[] entries = new MultiTagPubSearchCacheEntity[s.size()];
              int idx = 0;
              Iterator iter = s.iterator();
              while (iter.hasNext()) {
                   MultiTagPubSearchCacheEntity e = (MultiTagPubSearchCacheEntity)iter.next();
                   entries[idx] = e;
                   idx++;
              return entries;
         public static class ParallelResultObject implements ExternalizableLite {
              private MultiTagPubSearchCacheEntity[] entries;
              private int numEntries;
              public ParallelResultObject() {}
              public ParallelResultObject(MultiTagPubSearchCacheEntity[] entries, int numEntries) {
                   this.entries = entries;
                   this.numEntries = numEntries;
              public List generateResultList() {
                   ArrayList l = new ArrayList();
                   if(entries != null) {
                        for(int i=0;i<entries.length;i++) {
                             l.add(entries[i]);
                   return l;
              public MultiTagPubSearchCacheEntity[] getEntries() {
                   return entries;
              public int getNumEntries() {
                   return numEntries;
              public void readExternal(DataInput input) throws IOException {
                   int numEntries = ExternalizableHelper.readInt(input);
                   if(numEntries >0) {
                        MultiTagPubSearchCacheEntity[] entries = new MultiTagPubSearchCacheEntity[numEntries];
                        for(int i=0;i<numEntries;i++) {
                             entries[i] = (MultiTagPubSearchCacheEntity)ExternalizableHelper.readObject(input);     
                   this.entries = entries;
              public void writeExternal(DataOutput output) throws IOException {
                   if(numEntries >0) {
                        ExternalizableHelper.writeInt(output, numEntries);
                        for(int i=0;i<numEntries;i++) {
                             ExternalizableHelper.writeObject(output, entries[i]);     
                   } else {
                        ExternalizableHelper.writeInt(output, 0);
         public static class SortingParallelAggregator implements ExternalizableLite, EntryAggregator {
              private String sortFlag;
              private String ascDescFlag;
              public SortingParallelAggregator() {
                   super();
              public SortingParallelAggregator(String sortFlag, String ascDescFlag) {
                   super();
                   this.sortFlag = sortFlag;
                   this.ascDescFlag = ascDescFlag;
              public Object aggregate(Set entries) {
                   return sortEntries(entries, sortFlag, ascDescFlag);
              public void readExternal(DataInput input) throws IOException {
                   sortFlag = ExternalizableHelper.readSafeUTF(input);
                   ascDescFlag = ExternalizableHelper.readSafeUTF(input);
              public void writeExternal(DataOutput output) throws IOException {
                   ExternalizableHelper.writeSafeUTF(output, sortFlag);
                   ExternalizableHelper.writeSafeUTF(output, ascDescFlag);
              private ParallelResultObject sortEntries(Set entries, String sortFlag, String ascDescFlag) {
                   ArrayList sortedList;
                   ArrayList arrayList = new ArrayList(entries);     
                   if ( sortFlag != null && !"".equals(sortFlag.trim()) ) {
         if ( Cache_Query_Constants.DATE_SORT_FLAG.equals(sortFlag.trim().toUpperCase()) ) {
                             sortedList = sortByDate(arrayList, ascDescFlag);
         } else {
         sortedList = arrayList;
         } else {
         sortedList = arrayList;
                   return new ParallelResultObject(convertListToArray(sortedList), sortedList.size());
              private ArrayList sortByDate(ArrayList arrayList, String ascDescFlag) {
                   if("DESC".equals(ascDescFlag.trim().toUpperCase())) {
                        System.out.println("Start sort by DATE DESC");
                        Collections.sort(arrayList, new Comparator() {
                             public int compare(Object o1, Object o2) {
                                  int rc = 0;
                                  if((o1 instanceof MultiTagPubSearchCacheEntity) && (o2 instanceof MultiTagPubSearchCacheEntity))
                                       System.out.println("Sorting by MultiTagPubSearchCacheEntity ...");
                                       MultiTagPubSearchCacheEntity p1 = (MultiTagPubSearchCacheEntity) o1;
                                       MultiTagPubSearchCacheEntity p2 = (MultiTagPubSearchCacheEntity) o2;
                                       rc = p1.getPub_Date() - p2.getPub_Date();
                                       if ( rc == 0 ) {
                                            rc = p2.getTitle().compareTo(p1.getTitle());
                                  return rc;
                        Collections.reverse(arrayList);
                        System.out.println("Done sort by DATE DESC");
                   System.out.println("Size of sorted result : " + arrayList.size());
                   Iterator iter = arrayList.iterator();
                   while(iter.hasNext()) {
         InvocableMap.Entry entry = (InvocableMap.Entry)iter.next();
                        MultiTagPubSearchCacheEntity e = (MultiTagPubSearchCacheEntity)entry.getValue();     
         System.out.println("### Sorted Entries : " + e.toString());
                   return arrayList;
              private MultiTagPubSearchCacheEntity[] convertListToArray(ArrayList sortedList) {
                   MultiTagPubSearchCacheEntity[] entries = new MultiTagPubSearchCacheEntity[sortedList.size()];
                   Iterator iter = sortedList.iterator();
                   int idx = 0;
                   while(iter.hasNext()) {
                        InvocableMap.Entry e = (InvocableMap.Entry)iter.next();
                        entries[idx] = (MultiTagPubSearchCacheEntity)e.getValue();
                        idx++;
                   return entries;
    =========================================================

  • JDK 1.5 and TimeZone/sun.util.calendar.ZoneInfo issue

    Hi -
    I am working on a client/server application. The server code is being ported to JDK 1.5, but we need to support clients that are still running JDK 1.3. One of the issues we are facing is that the defaultTimeZone
    in JDK 1.5 has been changed to sun.util.calendar.ZoneInfo whereas
    the default in 1.3 is SimpleTimeZone.
    Does any one have an idea of how to convert an object that is of
    type sun.util.calendar.ZoneInfo to SimpleTimeZone?
    Many thanks for any inputs.

    http://forum.java.sun.com/thread.jspa?threadID=678742&messageID=3959360#3959360

  • Getting a  BEA-000802   java.lang.ClassCastException: in cluster mode only

    Guys ,
              I get a <BEA-000802> java.lang.ClassCastException in cluster mode , but works fine on a local instance. Please take a look at the stack trace below .
              <Error> <Kernel> <BEA-000802> <ExecuteRequest failed
              java.lang.ClassCastException: cannot assign instance of com.ibm.ie.web.presentation.IEPresentationCommandProcessor_814_WLStub to field com.ibm.web.servlet.Environment.presentationCommandProcessor of type com.ibm.web.presentation.PresentationCommandProcessor in instance of com.ibm.ie.web.servlet.IEEnvironment.
              java.lang.ClassCastException: cannot assign instance of com.ibm.ie.web.presentation.IEPresentationCommandProcessor_814_WLStub to field com.ibm.web.servlet.Environment.presentationCommandProcessor of type com.ibm.web.presentation.PresentationCommandProcessor in instance of com.ibm.ie.web.servlet.IEEnvironment
                   at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
                   at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:137)
                   at weblogic.cluster.replication.ReplicationManager_814_WLStub.update(Unknown Source)
                   at weblogic.cluster.replication.ReplicationManager.updateSecondary(ReplicationManager.java:775)
                   at weblogic.servlet.internal.session.ReplicatedSessionData.syncSession(ReplicatedSessionData.java:490)
                   at weblogic.servlet.internal.session.ReplicatedSessionContext.sync(ReplicatedSessionContext.java:183)
                   at weblogic.servlet.internal.ServletRequestImpl.syncSession(ServletRequestImpl.java:2484)
                   at weblogic.servlet.internal.ServletRequestImpl.syncSession(ServletRequestImpl.java:2469)
                   at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3782)
                   at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
                   at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
                   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
              Caused by: java.lang.ClassCastException: cannot assign instance of com.ibm.ie.web.presentation.IEPresentationCommandProcessor_814_WLStub to field com.ibm.web.servlet.Environment.presentationCommandProcessor of type com.ibm.web.presentation.PresentationCommandProcessor in instance of com.ibm.ie.web.servlet.IEEnvironment
                   at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:1885)
                   at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1076)
                   at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1851)
                   at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
                   at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
                   at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
                   at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
                   at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
                   at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
                   at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
                   at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1603)
                   at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1271)
                   at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
                   at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
                   at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
                   at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
                   at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
                   at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
                   at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
                   at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
                   at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
                   at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
                   at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
                   at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
                   at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
                   at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
                   at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
                   at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
                   at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
                   at java.util.HashMap.readObject(HashMap.java:1006)
                   at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:324)
                   at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:838)
                   at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1746)
                   at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
                   at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
                   at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
                   at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
                   at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
                   at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
                   at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
                   at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:120)
                   at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:120)
                   at weblogic.cluster.replication.ReplicationManager_WLSkel.invoke(Unknown Source)
                   at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:477)
                   at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:420)
                   at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
                   at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
                   at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:415)
                   at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
              Please advise , would be of help ..
              thanks a lot for taking a look
              s

    ####<Jan 19, 2007 2:55:00 AM CST> <Error> <Kernel> <bocephus.aus.lab.vignette.com> <Preview2DPMSrv> <ExecuteThread: '14' for queue: 'weblogic.kernel.Default'> <<WLS Kernel>> <> <BEA-000802> <ExecuteRequest failed
              java.lang.ClassCastException.
              java.lang.Throwable
                   at weblogic.servlet.internal.session.ReplicatedSessionContext.sync(ReplicatedSessionContext.java:175)
                   at weblogic.servlet.internal.ServletRequestImpl.syncSession(ServletRequestImpl.java:2581)
                   at weblogic.servlet.internal.ServletRequestImpl.syncSession(ServletRequestImpl.java:2566)
                   at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3920)
                   at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
                   at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
                   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
              >
              ####<Jan 19, 2007 2:55:12 AM CST> <Error> <Kernel> <bocephus.aus.lab.vignette.com> <Preview2DPMSrv> <ExecuteThread: '14' for queue: 'weblogic.kernel.Default'> <<WLS Kernel>> <> <BEA-000802> <ExecuteRequest failed
              java.lang.ClassCastException.
              java.lang.Throwable
                   at weblogic.servlet.internal.session.ReplicatedSessionContext.sync(ReplicatedSessionContext.java:175)
                   at weblogic.servlet.internal.ServletRequestImpl.syncSession(ServletRequestImpl.java:2581)
                   at weblogic.servlet.internal.ServletRequestImpl.syncSession(ServletRequestImpl.java:2566)
                   at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3920)
                   at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
                   at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
                   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
              I am getting these logs in domain.
              How to solve this problem.
              Thanks
              Somashekar

  • "ClassCastException" for items in List after serialization

    consider this code:
    public class MyClass implements Serializable {
      public double price = -1;
      public double volume = -1;
    List list = new ArrayList<MyClass>();
    while(!endOfData) {
      MyClass mc = new MyClass();
      mc.price = x;
      mc.volume = y;
      list.add(mc);
    ObjectOutputStream oos = new ObjectOutputStream(out);
    oos.writeObject(list);----
    and then the receiver-side:
    ObjectInputStream ois = new ObjectInputStream(in);
    List list = (List) ois.readObject();
    MyClass mc = (MyClass) list.get(2);
    ..... error ... error ...
    Exception in thread "Thread-1" java.lang.ClassCastException: MyClass
    note: using a Double instead of MyClass works ok.
    also please notice:
    ObjectInputStream ois = new ObjectInputStream(in);
    List list = (List) ois.readObject();
    Object mc = (Object) list.get(4);
    System.out.println("this is what i am --> " + mc.getClass().getCanonicalName());
    output: "this is what i am --> MyClass"
    thanks.
    Message was edited by:
    suppon

    the MyClass objects are not
    initially loaded in the receiver's JVM.Make a custom class as:
    public class CustomObjectInputStream extends ObjectInputStream {
        private ClassLoader classLoader;
        /** Creates a new instance of CustomObjectInputStream */
        public CustomObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException {
            super(in);
            this.classLoader = classLoader;
        protected Class<?> resolveClass(ObjectStreamClass desc) throws ClassNotFoundException {
            return Class.forName(desc.getName(), false, classLoader);
    }and use an instance of this class instead of the standard object inputstream to deserialize your object. You should pass the url class loader as an argument to the constructor of the custom object input stream. The reason is that the standard object inputstream only recognises classes that are "statically defined in the JAVA class path". (I quote the last text because I am not sure if I am using the right terminology, but I hope you understand what I mean.)
    why do i get
    "ClassCastExceptions" ??
    and not
    "ClassNotFoundException"
    ??This must be because somehow you have a "static" class definition for MyClass anyway, otherwise you wouldn't be able to write the following code and have it compile:
    MyClass item = (MyClass) class1.cast(list.get(7));Apparently your "static" MyClass definition does not correspond with the MyClass definition in your .jar file.
    You can only access a deserialized object of which the class definition is in a .jar file through reflection, unless you can cast it to an interface with a "static" definition.

  • Bizarre ClassCastException when sending serialized objects

    I have two programs communicating with each other over a network using TCP and serialized objects. One of the programs uses an ObjectOutputStream to send the message, and the other uses an ObjectInputStream to receive it. The receiver has a thread that simply loops, receiving and processing messages one at a time.
    Under normal circumstances, this works fine. However, sometimes the sender program has to send more than one message, one right after the other. I guess my assumption was that on the receiving end, they would somehow just "queue up" in the ObjectInputStream and the receiver would be able to read them one at a time. But instead, I get this bizarre ClassCastException whose message talks about members and objects from both messages that were sent. It is as though somehow the two objects received are being mangled together and interpreted somehow as one object. This is strange to me, since I am pretty sure TCP is supposed to guarantee in-order delivery of packets.
    Can I not send multiple messages right after each other through an ObjectOutputStream and have them received in an ObjectInputStream? If not, what would be a good workaround?
    If you need more details, it works like this. I have two classes that look like this:
    class Class1 extends SerializableSuperclass
      Member1 m1;
    class Class2 extends SerializableSuperclass
      Member2 m2;
    }Sender sends an instance of Class1 and then immediately an instance of Class2. Receiver attempts to readObject() from the input stream and gets this exception:
    Exception in thread "Thread-4" java.lang.ClassCastException: cannot assign instance of Class2 to field Class1.m1 of type Member1 in instance Class1
    Isn't that bizarre? Two separate classes, and it is attempting to merge the two in some odd way.
    How do I fix or work around this?
    Thanks

    These classes do not have those methods. They are simply message classes designed to hold data. Do you need to see the methods that call ObjectOutputStream's writeObject() and ObjectInputStream's readObject() methods?
    The serializable superclass is there because it has other stuff including a field identifying the sender. It's basically a base message class.
    Also, the member classes are serializable (serializability isn't the issue anyway; "class cast" is the issue).

  • Sun.util.calendar.ZoneInfo error

    I am getting the following error when I try to run a servlet that is supposed to get the current time and convert it automatically to GMT.
    Error invoking servlet
    sun.util.calendar.ZoneInfo:
    sun.util.calendar.ZoneInfo
    Here is the code:
    java.util.Date today;
    String result;
    SimpleTimeZone tz = (SimpleTimeZone)TimeZone.getTimeZone("EST");
    Calendar cal = Calendar.getInstance();
    int offset = -5;
    if (tz.useDaylightTime() && (tz.inDaylightTime(cal.getTime())))
    offset = -4;
    tz = new SimpleTimeZone(offset, "GMT");
    TimeZone.setDefault(tz);
    DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss z");
    formatter.setTimeZone(tz);
    today = new java.util.Date();
    result = formatter.format(today);
    Any help would be much appreciated.

    Don't use the sun.* classes, use the Calendar and related classes for this.

  • Getting  java.lang.ClassCastException during replication - 080003

    <Warning> <rmi> <080003> <RuntimeException thrown by rmi server: weblogic.cluster.replication.ReplicationManager.create(Lweblogic.rjvm.JVMID;ILweblogic.cluster.replication.ROID;Lweblogic.cluster.replication.Replicatable;)
              java.lang.ClassCastException: java.util.Hashtable
              java.lang.ClassCastException: java.util.Hashtable
              at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:99)
              at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:103)
              at weblogic.cluster.replication.ReplicationManager_WLSkel.invoke(Unknown Source)
              at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:455)
              at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:396)
              at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:726)
              at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:391)
              at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:251)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:219)
              >

    I use Jdev version 11.1.1.7. I use createRootApplicationModule to get an instance to AM to access its VOs and executeQuery on that.
    Am NOT using this in any VO implementation classes. I use this in a POJO class.
    Stack trace
    Caused By: java.lang.ClassCastException: oracle.jbo.common.ampool.PoolMgr
            at oracle.jbo.common.ampool.PoolMgr.getInstance(PoolMgr.java:76)
            at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1508)
            at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1485)
            at oracle.apps.scm.advancedPlanning.demandSnapshots.ess.program.DemandSnapshot.execute(DemandSnapshot.java:205)
            at oracle.apps.fnd.applcp.request.exec.AsyncExecutableWrapper.executeHelper(AsyncExecutableWrapper.java:162)
            at oracle.apps.fnd.applcp.request.exec.ExecWrapperBase.execute(ExecWrapperBase.java:156)
            at oracle.apps.fnd.applcp.request.exec.AsyncExecutableWrapper.execute(AsyncExecutableWrapper.java:139)
            at oracle.as.scheduler.rp.JavaSysExecWrapper$1.run(JavaSysExecWrapper.java:367)
            at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
            at oracle.security.jps.internal.jaas.AccActionExecutor.execute(AccActionExecutor.java:74)

  • ClassCastException returning XMLBeans from a jpd control

    hei,
    we are getting a classcastexception when we are returning a xmlbean from a jpd which is exposed as a control delivery project.
    usage scenario:
    1. a jpd is return a xmlbean.
    2. this jpd is exposed as a control delivery project to other applications.
    3. another jpd (in another application / another ear file) is using the process control.
    4. we get a classcastexception when we try to assign the returnvalue from the jpd to a variable of the type of the xmlbean.
    do we call the same jpd as a web service instead of using a control, we don't get the exception.
    Any ideas or glues?
    thanks
    Edited by toheller at 12/15/2006 1:00 AM
    Edited by toheller at 01/03/2007 1:01 AM
    Edited by toheller at 01/03/2007 4:50 AM
    Edited by toheller at 01/03/2007 4:51 AM

    Using the mechanism provided by WLI (the proxyfication of XMLBeans created from JPDs) is the best option, you should rely on it unless it is impossible to do so. What about instanciating the XMLBean from the JPD, passing it as a parameter to the control method, and filling up this XMLBean in the control? (or you can't because you are using a third-party control?)
    I have personally never tried the solution with the classpath, but a BEA engineer told us it would work.
    << How can I try this serialize/de-serialize workaround suggested? >>
    Probably something like this:
          XmlObject xmlObj = theXmlObjectReturned;
            ByteArrayOutputStream bos = null;
            ObjectOutputStream out = null;
            try {
                bos = new ByteArrayOutputStream();
                out = new ObjectOutputStream(bos);
                out.writeObject(theXmlObject);
                out.close();
            catch(IOException ex) {
                ex.printStackTrace();
            TheXmlDocument xmlDoc = null;
            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream in = new ObjectInputStream(bis);
            try {
                xmlDoc = (TheXmlDocument)in.readObject();
                in.close();
            catch(IOException ex)  {
                ex.printStackTrace();
            catch(ClassNotFoundException ex)  {
                ex.printStackTrace();
            }

  • SAXParserFactory ClassCastException

    I have the following method that throws the exception shown below:
    public static Object decodeString(String xmlString) {
         XMLDecoder xmlDecode = null;
         try {
              xmlDecode = new XMLDecoder(new BufferedInputStream(
                             new ByteArrayInputStream(xmlString.getBytes())));
              return xmlDecode.readObject();
         } finally {
              if (xmlDecode != null) {
                   xmlDecode.close();
    04/02/15 18:34:37 java.lang.ClassCastException
    04/02/15 18:34:37      at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:87)
    04/02/15 18:34:37      at java.beans.XMLDecoder.<init>(XMLDecoder.java:84)
    04/02/15 18:34:37      at java.beans.XMLDecoder.<init>(XMLDecoder.java:68)
    04/02/15 18:34:37      at java.beans.XMLDecoder.<init>(XMLDecoder.java:56)
    04/02/15 18:34:37      at com.avega.javax.XMLEncoders.decodeString(XMLEncoders.java:23)
    04/02/15 18:34:37      at com.avega.portlets.domain.UserDimensionSelections.getSelectionCriteria(UserDimensionSelections.java:98)The 'RecordSelectionCriteria' are being encoded properly and saved to the database, but when I try to decode them I get the exception. However, if I take the strings that are stored in the database and run the following test main method directly, it works:
    public static void main(String[] args) {
         String test =
              "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
              "<java version=\"1.4.1_02\" class=\"java.beans.XMLDecoder\">"+
              "<object class=\"java.util.ArrayList\">"+
              "<void method=\"add\">"+
              "<object class=\"com.avega.sql.RecordSelectionCriterion\">"+
              "<void property=\"value1\">"+
              "<string>Carefree</string>"+
              "</void></object></void></object>";
         String test2 =
              "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
              "<java version=\"1.4.1_02\" class=\"java.beans.XMLDecoder\">"+
              "<object class=\"java.util.ArrayList\">"+
              "<void method=\"add\">"+
              "<object class=\"com.avega.sql.RelativeTimeperiodCriterion\">"+
              "<void property=\"dateValue2\">"+
              "<object class=\"java.util.Date\">"+
              "<long>1075622399906</long>"+
              "</object>"+
              "</void>"+
              "<void property=\"numberOfUnits\">"+
              "<int>1</int>"+
              "</void>"+
              "<void property=\"timeUnit\">"+
              "<string>Months</string>"+
              "</void>"+
              "</object>"+
              "</void>"+
              "</object>";
         System.out.println(     ((RecordSelectionCriterion)((java.util.List)decodeString( test )).get(0)).getValue1() );
         System.out.println(     ((RelativeTimeperiodCriterion)((java.util.List)decodeString( test2 )).get(0)).getTimeUnit() );
    Ouput:
    org.xml.sax.SAXParseException: End of entity not allowed; an end tag is missing.
    Continuing ...
    Carefree
    org.xml.sax.SAXParseException: End of entity not allowed; an end tag is missing.
    Continuing ...
    MonthsWhy would the 'main' method work, but the same method throws the exception when called from my application (running in Embedded OC4J)?
    I even added a println with SAXParserFactory.newInstance().toString() to confirm that in both cases the SAXParserFactory is oracle.xml.jaxp.JXSAXParserFactory. The main method also works if I run the class directly on the commandline, and there the factory is org.apache.crimson.jaxp.SAXParserFactoryImpl.

    First you need to close the <java> tag on your test Strings.
    Then the class named RecordSelectionCriterion must be in your classpath. As well as the class called RelativeTimeperiodCriterion.
    For example, I create a Bean like:
    package mypackage1;
    public class RecordSelectionCriterion
    String value1;
    public RecordSelectionCriterion()
    public String getValue1()
    return value1;
    public void setValue1(String value1)
    this.value1 = value1;
    and another one like:
    package mypackage1;
    import java.util.Date;
    public class RelativeTimeperiodCriterion
    Date dateValue2;
    int numberOfUnits;
    String timeUnit;
    public RelativeTimeperiodCriterion()
    public Date getDateValue2()
    return dateValue2;
    public void setDateValue2(Date dateValue2)
    this.dateValue2 = dateValue2;
    public int getNumberOfUnits()
    return numberOfUnits;
    public void setNumberOfUnits(int numberOfUnits)
    this.numberOfUnits = numberOfUnits;
    public String getTimeUnit()
    return timeUnit;
    public void setTimeUnit(String timeUnit)
    this.timeUnit = timeUnit;
    Then the code:
    package mypackage1;
    import java.beans.XMLDecoder;
    import java.io.BufferedInputStream;
    import java.io.ByteArrayInputStream;
    public class saxotn
    public saxotn()
    public static Object decodeString(String xmlString) {
    XMLDecoder xmlDecode = null;
    try {
    xmlDecode = new XMLDecoder(new BufferedInputStream(
    new ByteArrayInputStream(xmlString.getBytes())));
    return xmlDecode.readObject();
    } finally {
    if (xmlDecode != null) {
    xmlDecode.close();
    public static void main(String[] args) {
    String test =
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
    "<java version=\"1.4.1_02\" class=\"java.beans.XMLDecoder\">"+
    "<object class=\"java.util.ArrayList\">"+
    "<void method=\"add\">"+
    "<object class=\"mypackage1.RecordSelectionCriterion\">"+
    "<void property=\"value1\">"+
    "<string>Carefree</string>"+
    "</void></object></void></object>" +
    "</java>";
    String test2 =
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
    "<java version=\"1.4.1_02\" class=\"java.beans.XMLDecoder\">"+
    "<object class=\"java.util.ArrayList\">"+
    "<void method=\"add\">"+
    "<object class=\"mypackage1.RelativeTimeperiodCriterion\">"+
    "<void property=\"dateValue2\">"+
    "<object class=\"java.util.Date\">"+
    "<long>1075622399906</long>"+
    "</object>"+
    "</void>"+
    "<void property=\"numberOfUnits\">"+
    "<int>1</int>"+
    "</void>"+
    "<void property=\"timeUnit\">"+
    "<string>Months</string>"+
    "</void>"+
    "</object>"+
    "</void>"+
    "</object>" +
    "</java>";
    System.out.println(test);
    Object o1 = ((java.util.List)decodeString( test ));
    System.out.println(test2);
    Object o2 = ((java.util.List)decodeString( test2 ));
    works fine for me.
    Hope the addresses your point,
    - Olivier

  • Getting :java.lang.ClassCastException: weblogic.rmi.internal.MethodDescript

    Hi I am getting the following exception:
    java.lang.ClassCastException: weblogic.rmi.internal.MethodDescriptor
         at weblogic.rjvm.MsgAbbrevInputStream.readClassDescriptor(MsgAbbrevInputStream.java:186)
         at weblogic.common.internal.ChunkedObjectInputStream$NestedObjectInputStream.readClassDescriptor(ChunkedObjectInputStream.java:300)
         at java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:901)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:361)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)
         at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1181)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:381)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)
         at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:110)
         at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:123)
         at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:298)
         at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
         at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:267)
         at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    can any body explain the Cause for this exception and what will be the impact on the server.
    but if i restart the server the error is not coming

    Hi I am getting the following exception:
    java.lang.ClassCastException: weblogic.rmi.internal.MethodDescriptor
         at weblogic.rjvm.MsgAbbrevInputStream.readClassDescriptor(MsgAbbrevInputStream.java:186)
         at weblogic.common.internal.ChunkedObjectInputStream$NestedObjectInputStream.readClassDescriptor(ChunkedObjectInputStream.java:300)
         at java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:901)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:361)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)
         at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1181)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:381)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)
         at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:110)
         at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:123)
         at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:298)
         at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
         at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:267)
         at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    can any body explain the Cause for this exception and what will be the impact on the server.
    but if i restart the server the error is not coming

  • RMI ClassCastException

    Hello, world!
    My problem is the following: I'm developping a peer-to-peer application based on RMI. This application includes applets -called peerlets- that can be exposed to and used by other peers. Hence I have two remote interfaces:
    public interface Peerlet extends Remote {
        // stuff that throws RemoteException
    public interface Peer extends Remote {
        public Peerlet getPeerlet(/*some Peerlet ID here*/) throws RemoteException;
    }As you can see Peer is the broker that passes references on local peerlets to remote peers. There are many possible peerlets, such as:
    public interface APeerlet extends Peerlet {
        // stuff that throws RemoteException
    }Creating a Peer instance, retrieve it from another remote Peer instance via RMI is fine. My problem occurs when I try to get references on remote peerlets. Concretely the situation is the following:
    - peerA and peerB are two running Peer instances, they have a reference on each other; peerA hosts a APeerlet.
    - if peerB tries the following:
    Peerlet p = (APeerlet) peerA.getPeerlet(/*appropriate ID to get the desired APeerlet*/);
    //...everything goes fine, peerB can use p normaly. But this is not what I want, since this piece of code needs to have APeerlet defined. If I try to get simply a Peerlet - that would be used latter by another piece of code who knows what to do with a APeerlet - ie:
    Peerlet p = (Peerlet) peerA.getPeerlet(/*...*/);
    //...I get a
    java.lang.ClassCastException: $Proxy3 cannot be cast to ....PeerletI guess it's a class loading issue, but I can't figure out why the cast to Peerlet fails whereas a cast to APeerlet does not. I have found interesting behaviour with this two variations in peerB's code:
    import ....APeerlet;
    Class<? extends Peerlet> clazz = APeerlet.class;
    Peerlet p = clazz.cast(peerA.getPeerlet(/*...*/););
    // no import ....APeerlet;
    Class<? extends Peerlet> clazz = /*something that returns me APeerlet.class*/;
    Peerlet p = clazz.cast(peerA.getPeerlet(/*...*/););The first version is still not what I want since it needs a definition of APeerlet, but it works. The second one throws ClassCastException... I have hidden many details, such as the http server I use for dynamic class loading; it does not receive the same queries when the ClassCastException is thrown. Could it be the source of my trouble?
    S
    Edited by: sylf on Aug 14, 2010 3:09 PM

    I see your point. Only Peer should be in the codebase, since it is the only class bound to the RMIRegistry, Peerlet and APeerlet should NOT be in the codebase but only in the classpath of both peers.
    However, if Peerlet is not in the codebase, I get a ClassNotFoundException : Peerlet at startup, since the Peer interface uses Peerlet as a return type of Peer.getPeerlet(...). So I had no choice but to keep Peerlet in the codebase, and now peerB gets a ClassNotFoundException : APeerlet when trying to get a APeerlet from peerA...
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
            java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
            java.lang.ClassNotFoundException: ....APeerlet
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:336)
            at sun.rmi.transport.Transport$1.run(Transport.java:159)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
            at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
            at java.lang.Thread.run(Thread.java:619)
            at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
            at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
            at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160)
            at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
            at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
            at $Proxy0.getPeerlet(Unknown Source)
            at ...Peer.getPeerlet(Peer.java:112)
            at //...
    Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
            java.lang.ClassNotFoundException: ...APeerlet
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:296)
            at sun.rmi.transport.Transport$1.run(Transport.java:159)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
            at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
            at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.ClassNotFoundException: ...APeerlet
            at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:247)
            at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:434)
            at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
            at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
            at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
            at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
            at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
            at java.io.ObjectInputStream.readClass(ObjectInputStream.java:1462)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1312)
            at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
            at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
            at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:306)
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:290)
            ... 9 moreIt looks like it's the RMIServer who can't find APeerlet... but why?
    I get the same Exception after having changed the return type of Peer.getPeerlet() to Remote so that Peerlet has not to be in the codebase anymore.
    S

Maybe you are looking for

  • How do you get Workforce 840 to print two-sided

    I can't figure out how to get my new Epson Workforce 840 to print two-sided (iMac running Mac OS 10.7.2).  From MS Word the two-sided option (in Layout) is grayed out.  In Mail and other Apple applications the Preset for two-sided printing is off and

  • How to restrict the default selection of first row in ALV  in Webdynpro

    Hi Experts, In webdynpro i used ALV to display the bulk amount of datas under a view container. While running it ll cme by default selection on first row. how to restrict that.....

  • Stop printing of Invoice and Payment from Sales Order

    When creating a Sales Order, the user can enter a "downpayment' in the Payment Means window. When doing this 8.8 will create an AR Downpayment Invoice + Payment. When the user prints the Sales Order, SAP/b1 will also print the invoice and the payment

  • Lithtroom 5.X exit problem

    After some random time, I can't exit Lr trough File Menu/Exit, or even if I use shortcut Ctrl Q. Instead of that, LR applies preset. I have same problems with W7, W8, Lr4, Lr5. Maybe the bigger amount of my presets crashes a part of Lr. Other functio

  • IDE:  Child movieclip timeline changes don't show in parent timeline?

    Why does a child movieclip only show the first frame within the IDE, regardless of where you are in the parent timeline? If you throw a movieclip with 25 frames onto the main timeline, which also has 25 frame, you don't see the nested movieclip's fra