Why ClassCastException is thrown?

Sometimes when I use stop+ function of MediaPlayer class media is stoped playing and then playing again. After several traying to stop this behavior by pressing my stop button I've stopped application and got this information as an output:
java.lang.ClassCastException: com.sun.scenario.effect.impl.j2d.J2DCropPeer cannot be cast to com.sun.scenario.effect.impl.j2d.rsl.RSLEffectPeer
        at com.sun.scenario.effect.impl.j2d.rsl.RSLRenderer.dispose(RSLRenderer.java:152)
        at com.sun.scenario.effect.impl.j2d.rsl.RSLRenderer$1.onDeviceReset(RSLRenderer.java:83)
        at sun.java2d.pipe.hw.AccelDeviceEventNotifier.notifyListeners(AccelDeviceEventNotifier.java:143)
        at sun.java2d.pipe.hw.AccelDeviceEventNotifier.eventOccured(AccelDeviceEventNotifier.java:77)
        at sun.awt.windows.WToolkit.eventLoop(Native Method)
        at sun.awt.windows.WToolkit.run(WToolkit.java:291)
        at java.lang.Thread.run(Thread.java:619)What you thinking about it? Any sensible opinions are welcomed!
I use JavaFx 1.2, IDE Netbeans 6.8

This is a similar run-time error I was getting.
I assumed it had something to do with a view node that I created with an effect.
If I placed an input node (like a text box control or list etc..) on top of a node that had an effect, I would get run-time errors. Sometimes the application would freeze right up.
So for example, if I had a rectangle with a reflection, and I placed a text box in a group with it, with the rectangle behind the text box, once in a while I would receive a similar error.
Don't know if this helps. This is something I am curious about as well.

Similar Messages

  • Wait - interrupt  Why Exception not thrown?

    Hello. I expected that calling interrupt() on a waiting thread should result in InterruptedException thrown by wait(). Nevertheless, in the code below no Exception is thown as if there were no interrupt() call. Actually this snippet prints the same output irregardless of whether interrupt() is called.
    public class Runner {
        synchronized public void foo(){
            System.out.println("before wait in foo()");
            try {
                wait();
            } catch (InterruptedException e) {
                System.out.println("InterruptedException");
                e.printStackTrace();
            System.out.println("after wait in foo()");
        synchronized public void bar(){
            System.out.println("before sleep in bar()");
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            System.out.println("after sleep in bar()");
            notify();
            System.out.println("after notify in bar()");
        public static void main(String[] args) {
            final Runner runner = new Runner();
            Thread t1 = new Thread(new Runnable(){
                public void run() {
                    runner.foo();
            Thread t2 = new Thread(new Runnable(){
                public void run() {
                    runner.bar();
            t1.start();
            t2.start();
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            t1.interrupt();
            System.out.println("t1 interrupted");
    }

    Thanks for your response.
    Still the whole thing is not clear to me.
    Why InterruptedException is not deterministic in this
    case?
    Where is the ?non-deterministic? code in this
    example?The fact that t1.start() is written before t2.start() in you code does not guarantee that foo() method will always be called first. Either the bar() method or foo() method can be invoked firstly, because this is how threads work in Java. Try to invert: put t2.start() before t1.start(), and see what happens. Probably the exception will be thrown in this case, but this behaviour is still non deterministic.
    Please pay attention to timing -
    t1.interrupt() is called in about 5 seconds after
    both threads are started, at the time when one thread
    is in sleep(10000) and the other in wait(). I believe
    that above condition may be taken for granted taking
    in account 5 seconds interval between calls.You know that when you invoke the notify() method inside the bar method() you are making the foo() method not waiting anymore, don?t you? Therefore, if foo() method is called firstly, then the InterruptedException probably won?t be thrown. I said "probably" because the behaviour is non deterministic. Time is relative. If your processor is fast, then probably the exception will never be thrown, but you will never be completely sure. Maybe if there are other executions using your processor, then the processor might be slow for your program, and then the InterruptedException might be thrown. If you want to make your program have the same behaviour always, then you have to use semaphore variables, that indicate when exactly one thread is permitted to run.

  • Servlet -- HttpSession -- JSP , Why ClassCastException

    When I put an object in the HttpSession in a servlet and try to get it
    (and casting) , in a JSP within the same session, i get ClassCastException,
    any body knows the problem?
    thanks,
    ali.

    What WL version you runing? Is this object in your CLASSPATH?
    Gene
    "ali" <[email protected]> wrote in message news:3a8c5e32$[email protected]..
    When I put an object in the HttpSession in a servlet and try to get it
    (and casting) , in a JSP within the same session, i get ClassCastException,
    any body knows the problem?
    thanks,
    ali.

  • Why is IllegalStateException thrown in this Java Code Snippet ?

    This is one of the questions in a mock test.
    void waitForSignal()
        Object obj=new Object();
        synchronized(Thread.currentThread())
               obj.wait();
               obj.notify();
    Which statement is true ?
    A. This code may throw and InterruptedException
    B. ThHis code may throw and IllegalStateEXception
    C. This code may throw and TimeOuException after 10  minutes
    D. This code will not compile unless "obj.wait()" is replaced with "((Tread)obj)
         .wait()"
    E. Reversing the order of obj.wait() and obj.notify() may cause this method    to         complete normally
    Answer : BSo why won't the code throw interrupted exception and throws a illegal state exception.
    Also,some pointer to thread's wait() and notify() would help greatly.
    Thank you for your consideration.

    You must have the lock on an object before you can call wait or notify. The code doesn't synchronize on obj.
    Kaj

  • Why do I get a ClassCastException using JNDI between ears?

    This is an issue that has bothered me for almost a year. It comes up every once in a while and usually I can find a workaround, but I need to understand what is causing the failure.
    Here is the problem description as an abstract example:
    I have two WAR files deployed on WL (8.1 sp3), WarA and WarB.
    In a servlet in WarA, I execute the following:
      Context context = new InitialContext();
      MyObject myObj = new MyObject();
      context.bind("myObject", myObj);Then, in a servlet in WarB, I execute the following, receiving a ClassCaseException on the last line of code:
      Context context = new InitialContext();
      Object obj = context.lookup("myObject");
      MyObject myObj = (MyObject)obj;  //ClassCastException!!Of course I have deployed MyObject.class in a jar file inside the WEB-INF/lib of each WAR.
    I understand that each WAR file uses a seperate ClassLoader, but I do not understand why the object's class is not recognized when it is retrieved. I have tried several debugging methods (obj.getClass().getName() or halting execution using a debugger and looking at the object's class signature). In every instance the classname looks correct, exactly as I would expect it to, but the ClassCastException is thrown anyways.
    In the past I have "copped out" by creating an EAR, putting both WARs in the EAR, and adding the jar containing MyObject to the APP-INF/lib.
    Unfortunately the most recent occurrence of this problem is more complex and I do not have the luxury of my standard workaround. Can someone please fill in the blanks of what elementary concept I am overlooking?
    Thanks
    JB

    I don't think the classloader-structure tag is exactly what I am looking for. Based on the documentation I reviewed on the edocs site, that solution appears to make sense if you are manipulating numerous classloaders within a specific ear.
    I suppose you could try to use the classloader-structure to reference a classloader from a seperate application, but the docs do not indicate that this is a possibility. Moreover, it seems dangerous and potentially very confusing.
    Ultimately, I think this boils down to a lesson for me about classloaders. Unless someone can tell me otherwise, I am ready to concede that you cannot access/cast an object that you have bound to the JNDI tree in one application from within any other application. The notable exception to this rule is the scenario where the class type to which you are casting is a class that is loaded by the system classloader.
    This makes some sense to me - each standalone war or ear is independent of other wars/ears deployed on the app server. But, it is also somewhat frustrating because you cannot share global services across a suite of applications via JNDI unless you bundle them all as a single ear.

  • ClassCastException with ClassLoader issues

    I'm using JBoss 3.2.3, with Kodo 3.1.0
    After doing a hot deploy in JBoss, ClassCastExceptions start occuring.
    String filter = "reference==param1";
    Extent extent = pm.getExtent(Customer.class, false);
    KodoQuery query = (KodoQuery) pm.newQuery(extent, filter);
    Collection col = null;
    try {
    query.declareParameters("String param1");
    col = (Collection) query.execute("x34c");
    if (col.isEmpty())
    return null;
    Customer cust = (Customer) col.iterator().next();
    finally {
    if (query != null)
    query.close(col);
    At the line: Customer cust = (Customer) col.iterator().next();
    a ClassCastException is thrown. The class loader for Customer.class point
    to the deployed ear file, whilst the loader for
    col.iterator().next().getClass() points to null.
    Now, what is even more interesting is if I amend the above code slightly:
    Extent extent = pm.getExtent(Customer.class, false);
    KodoQuery query = (KodoQuery) pm.newQuery(extent);
    Collection col = null;
    try {
    col = (Collection) query.execute();
    if (col.isEmpty())
    return null;
    Customer cust = (Customer) col.iterator().next();
    finally {
    if (query != null)
    query.close(col);
    With the above, everything works fine. The only difference is that one
    uses a filter to retrieve a particular object from the datastore, and the
    other retrieves all objects from the datastore. I don't understand why it
    throws a ClassCastException in one instance and not the other. Note that
    this only happens after a hot deploy.
    This problem only surfaced recently after I added a few more classes to be
    persistent capable. After adding a further two classes, the
    ClassCastException moved to another class.
    Can anyone explain this?
    Cheers

    A N-
    Did you make absolutely sure that you enhanced all of the new classes
    and deployed them to correctly, and that you have clobbered any caches
    JBoss may have to any of the old .ear files?
    It might be the case that when you obtain the first in the list of all
    the Customer instances, it doesn't have a relation to one of the new
    classes, or its concrete instance is not one of the new classes, as
    opposed to when you execute the filter.
    If this doesn't help, can you provide us with some more information? At
    a minimum, a complete stack trace is usually a prerequisite for being
    able to diagnose problems like this.
    In article <[email protected]>, A N wrote:
    >
    I'm using JBoss 3.2.3, with Kodo 3.1.0
    After doing a hot deploy in JBoss, ClassCastExceptions start occuring.
    String filter = "reference==param1";
    Extent extent = pm.getExtent(Customer.class, false);
    KodoQuery query = (KodoQuery) pm.newQuery(extent, filter);
    Collection col = null;
    try {
    query.declareParameters("String param1");
    col = (Collection) query.execute("x34c");
    if (col.isEmpty())
    return null;
    Customer cust = (Customer) col.iterator().next();
    finally {
    if (query != null)
    query.close(col);
    At the line: Customer cust = (Customer) col.iterator().next();
    a ClassCastException is thrown. The class loader for Customer.class point
    to the deployed ear file, whilst the loader for
    col.iterator().next().getClass() points to null.
    Now, what is even more interesting is if I amend the above code slightly:
    Extent extent = pm.getExtent(Customer.class, false);
    KodoQuery query = (KodoQuery) pm.newQuery(extent);
    Collection col = null;
    try {
    col = (Collection) query.execute();
    if (col.isEmpty())
    return null;
    Customer cust = (Customer) col.iterator().next();
    finally {
    if (query != null)
    query.close(col);
    With the above, everything works fine. The only difference is that one
    uses a filter to retrieve a particular object from the datastore, and the
    other retrieves all objects from the datastore. I don't understand why it
    throws a ClassCastException in one instance and not the other. Note that
    this only happens after a hot deploy.
    This problem only surfaced recently after I added a few more classes to be
    persistent capable. After adding a further two classes, the
    ClassCastException moved to another class.
    Can anyone explain this?
    Cheers
    Marc Prud'hommeaux [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • Exception while casting int[] to Object[],why?

    if(params.getClass().isArray()) this.params = (Object[])params;
    else this.params = new Object[]{params};
    Now I transfer int[] as "params",and ClassCastException is thrown while casting params to Object[].Since I'm using JDK5.0,why does this happen(the array has been initialized)?

    But how to retrieve every element of this
    Object(Array)? Which type should you cast it to?int[] obviously. Or forget about casting and simply create an Integer[] yourself. a for loop isn't that difficult to write.
    Are you aware that arrays are objects? That's why java doesn't autobox an int[].
    By the way, you should look at these lines of code again:
    if(params.getClass().isArray())
    this.params = (Object[])params;
    else this.params = new Object[]{params};

  • UID key in TreeMap causing ClassCastException

    Hello all,
    I'm trying to use the UID class as a key in a TreeMap, but I'm running into a ClassCastException when I try to lookup using a UID as a key. From the docs, I see that a ClassCastException is thrown when the "key cannot be compared with the keys currently in the map." My guess is that the key needs to implement the comparable interface but I can't find mention of it anywhere in the docs. (other than the 'compared with keys' statement) ... So, two questions:
    1) Can someone verify my suspicions about comparable interface?
    2) Is there a better solution that implementing my own 'comparable subclass of UID? (I don't mind subclassing, but I'm loath to write/maintain/test/document a custom solution if I can use a built in class)
         protected void testTreemapUID() {
              TreeMap tree = new TreeMap();
              Double testDouble = new Double(23);
              tree.put( testDouble, new String("frank"));
              String result = (String)tree.get(testDouble);
              System.out.println("about to get value from Double " );
              System.out.println("Double result = " + result );
              tree = new TreeMap();
              UID uid = new UID();
              tree.put(uid, new String("bob"));
              System.out.println("about to get value from UID " );
              result = (String)tree.get( uid );
              System.out.println("UID result = " + result );
         }console output:
    about to get value from Double
    Double result = frank
    about to get value from UID
    Exception in thread "main" java.lang.ClassCastException: java.rmi.server.UID
         at java.util.TreeMap.compare(TreeMap.java:1093)
         at java.util.TreeMap.getEntry(TreeMap.java:347)
         at java.util.TreeMap.get(TreeMap.java:265)
         at SandBoxTester.testTreemapUID(SandBoxTester.java:70)
         at SandBoxTester.<init>(SandBoxTester.java:53)
         at SandBoxTester.main(SandBoxTester.java:100)
    as always, many thanks!
    Message was edited by:
    oldmicah

    Because you are using a TreeMap, which is a sorted map, the keys must be mutually comparable.
    java.rmi.server.UID doesn't implement Comparable. That's why the ClassCastException is thrown.
    If you need a sorted map, then you will have to provide a Comparator*.
    If you don't care about sorting, you could use a HashMap instead.

  • Unexpected ClassCastException when looking up Home using JNDI

    J2EE Gurus,
    In the attached sample program, a EJB (named MyScheduler in package mytest) is
    used to install a java code dynamically in weblogic service (8.1sp1), as well
    as to invoke a test java code (MyTest.run()) in it using Java reflection. Another
    EJB (named MyEJB in package myejb) is deployed dynamically using Weblogic console
    with its client side packaged with dynamically deployed java code. When invoked
    through MyScheduler, MyTest.run() simply looks up the home of MyEJB using JNDI,
    and when it is cast to MyEJBHome, a ClassCastException is thrown.
    Can someone explain why this exception occurs? Does this mean that a (dynamically)
    deployed code (java or EJB) cannot call other (dynamically) deployed EJBs, even
    when it has the client side of EJB packaged with it?
    Any help will be deeply appreciated.
    Thanks,
    Abhay
    [testjava.jar]

    "Nick" <[email protected]> wrote in message news:40343200$[email protected]..
    Because returned instance implements javax.sql.DataSource.Ha ha.
    No kidding :-)No. One could have found it himself by printing out returned type class
    or just by going to google and typing XADataSource weblogic +ClassCastException...
    Why would you want to do it? weblogic takes care of all the XA
    connection pooling, resource enlistments etc.Yeah, true.
    I should know this - I just got a little confused ... :-)
    I have just come from doing all the XA stuff myself... and got used to having
    XADataSources around...Thanks to J2EE, there is no need for low level plumbing when transaction
    support is needed.
    Also, with JMS resources, you DO have to have the XAQueueConnection etc etc for
    XA - even in an appserver.Per my knowledge weblogic allows you creating XA-aware JMS resources.
    Regards,
    Slava Imeshev
    >
    Thanks.
    "Slava Imeshev" <[email protected]> wrote:
    "Nick" <[email protected]> wrote in message news:403121e2$[email protected]..
    I am getting a ClassCast exception when I lookup a "Global Transaction"enabled
    JDBC DataSource.
    XADataSource xads = (XADataSource) ctx.lookup("jdbc/MyDS");
    Why is this?Because returned instance implements javax.sql.DataSource.
    How do I configure an XADataSource in JNDI?Why would you want to do it? weblogic takes care of all the XA connection
    pooling, resource enlistments etc.
    Regards,
    Slava Imeshev

  • 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

  • ClassCastException when classes (and classloaders) match. Confused.

    Hi,
    I am callng a method on an object using reflection. I then cast the resultant object. This cast gives me a ClassCastException. However I have added some debugging code as I suspected the Class of the object being cast was the same as the target cast too.
    The class being cast to is called es.shared.ESData and when I try
    object instanceof es.shared.ESData I get True.
    So the object is of the correct Class (and is not null) so why would the cast fail ? I thought maybe they have different ClassLoaders so I got my code to print the following
    object.getClass().getClassLoader() ;
    ESData.class.getClassLoader();and the classlaoders are the same. So I have object of the type es.shared.ESData that when I try and cast it to es.shared.ESData a ClassCastException is thrown.
    Can anyone help me understand why this would happen ? I have googled and found nothing of help, but then it is a very hard query to raise for google.
    Regards
    Russell
    PS the code looks a little like this
    Method method = serviceObject.getClass().getMethod("doESRequest", new Class[] { esData.getClass() });
    Object result = method.invoke(serviceObject, new Object[] { esData });
    System.out.println((result instanceof es.shared.ESData));//this always prints True
    System.out.println((result == null));//this is false!
    System.out.println(ESData.class.getClassLoader() + " = " +result.getClass().getClassLoader()); //these always match!
    ESdata esDataResult = (ESData)result;//ClassCastException!

    I noticed you ahve different spelling on the class name. Is that the problem? See ESdata vs ESData!
    ESdata esDataResult = (ESData)result;//ClassCastException!

  • Problem with ClassCastException in web application

    Hello,
              I'm trying to deploy a web application in WLS 5.1 and I'm getting the
              "dreaded" ClassCastException every time when JSP tries to read a bean
              from the request or session. Under my architecture (actually it's just
              the regular "model 2" ) bean is populated by a servlet, set on the
              request and then retrieved by JSP (servlet forwards to JSP). Everything
              work fine when I register servlets in weblogic.properties, but
              ClassCastException is thrown on any attempt to read from the request if
              the same JSPs and servlets are deployed as web application.
              Has anybody come across the same problem?
              Thanks in advance for help.
              Alexander
              

    Hello,
              This is all well and good as a temporary bug, but it's totally unrealistic for
              the future. Two points:
              * The ClassLoader doesn't need to be discarded, it just needs to be cleared.
              * Other servlet engines seem to be able to handle this.
              Hope it's on its way to resolution!
              TDoan wrote:
              > Alexander:
              >
              > I had some problem with ClassCastException, and recently I found out what it
              > was that causing it. I'm sure if this is the same problem you are having,
              > but please read the following paragraph.
              >
              > I cutted this from http://www.weblogic.com/docs51/classdocs/API_servlet.html
              > ClassCastException and HTTP Sessions
              >
              > You might encounter a ClassCastException while developing servlets that use
              > HTTP sessions. This could happen as a result of the following set of events:
              >
              > a.. You store a reference to a custom class, myFoo, in an HTTP session.
              >
              > b.. While in mid-session, you change your servlet (or JSP or JHTML),
              > causing it to be reloaded. In fact, it is necessary for it to be reloaded by
              > a completely new class loader, and the old class loader that had previously
              > loaded it must be discarded.
              >
              > c.. Because your custom class myFoo is also located under the servlet
              > classpath, it too is reloaded by the new class loader.
              >
              > d.. Now, when you retrieve myFoo from the HTTP session, you cast it to the
              > expected type, but you recieve a ClassCastException. The exception is thrown
              > even if class myFoo has not changed. Because it has been loaded by a
              > different class loader, it is regarded by the JVM as incompatible.
              > Note: If you are using session persistence, the class contents must be
              > serialized, and you will not encounter this exception.
              >
              > Here are some suggested work-arounds to this problem:
              >
              > a.. Do not place your class myFoo in the servlet classpath. Instead, place
              > it in the system classpath or the weblogic.class.path, which are accessible
              > by WebLogic Server. The class will not be reloaded when the servlet is
              > modified. This drawback to this solution is that you cannot prototype the
              > myFoo class, because you must restart the server in order to reload the
              > class after it is modified.
              >
              > b.. If you need to prototype the class, you can write a wrapper method
              > within it to store and retrieve its contents to and from the session. You do
              > not access the class directly from the session, but instead call it is
              > wrapper methods to store or populate it is contents from the session. As
              > long as you use standard Java class types to store the class contents, they
              > will not be reloaded when the servlet is reloaded. This approach has
              > performance drawbacks because your wrapper methods would need to set or get
              > multiple name=value pairs for each class's attributes.
              >
              > c.. Another work-around is to catch the ClassCastException, and replace
              > the old class that is stored in the session with a newly instantiated class,
              > or remove it from the session. Unfortunately, you lose the session data that
              > was previously stored in the class, so you must write your application to
              > handle this scenario. This is the easiest solution to the problem-remember
              > that you should not be storing critical information in an HTTP session, but
              > rather storing it in a database.
              > Note: The ClassCastException generally occurs while you are developing
              > your servlets, and should not be an issue in a stable production system. If
              > you are upgrading your system online, you might wish to warn your customer
              > base.
              >
              > Hope it helps,
              > Tin
              >
              > "Alexander Ananiev" <[email protected]> wrote in message
              > news:[email protected]...
              > > Hello,
              > >
              > > I'm trying to deploy a web application in WLS 5.1 and I'm getting the
              > > "dreaded" ClassCastException every time when JSP tries to read a bean
              > > from the request or session. Under my architecture (actually it's just
              > > the regular "model 2" ) bean is populated by a servlet, set on the
              > > request and then retrieved by JSP (servlet forwards to JSP). Everything
              > > work fine when I register servlets in weblogic.properties, but
              > > ClassCastException is thrown on any attempt to read from the request if
              > > the same JSPs and servlets are deployed as web application.
              > > Has anybody come across the same problem?
              > >
              > > Thanks in advance for help.
              > > Alexander
              > >
              

  • ClassCastException, and we *are* using "-Djbo.server.in_oc4j=true "

    Hi,
    We have several applications using the same BC4J objects running on the same AppSer (Oracle9iAS Containers for J2EE 9.0.2.0.0, running on Ibm AIX 4.3.3).
    Each time we deploy a specific application, all OTHER applications get ClassCastExceptions, like
    "java.lang.ClassCastException: <myPackage>.<myTable>ViewRowImpl"
    We DO start OC4J with the -Djbo.server.in_oc4j=true option.
    Any ideas?
    Regards,
    Jaime Conejo/ Martijn Hinten

    Hi,
    I already tried this, but the getClass() method reports exactly the class as I am expecting! To be more precise:
    I am executing the following code:
    ApplicationModule am;
    ViewObject vo;
    VCboLookupArtFeViewRow titelRow; // This is an interface, which is implemented by
    // VCboLookupArtFeViewRowImpl
    vo = am.findViewObject("VCboLookupArtFeView");
    Sytem.out.println("rowtype:"+vo.first().getClass()); // (1)
    titelRow = (VCboLookupArtFeViewRow) = vo.first(); // (2)
    Now, at line (1) the console reports that the object type is is 'com.centraalboekhuis.cbonline.model.VCboLookupArtFeViewRowImpl'. Note this is the "impl" class that implements my VCboLookupArtFeViewRow-interface. I am not casting to the "impl" class, as the Bc4j manual tells me I should use the interface instead (which makes sense). So, I am casting to an interface reference type, which my class implements. Should work.
    However at line (2) the following ClassCastException is thrown (see below). It tells me my object is not a VCboLookupArtFeViewRowImpl. But I now it is, as my debug statement tells me it is. Again, I am casting to an interface type, but VCboLookupArtFeViewRowImpl implements this interface type, so this should work. As a proof that it indeed works I can demonstrate that when I deploy my application all works fine, but when another project member deploys his application, my application fails with the ominous ClassCastException.
    So, what is happening here?
    java.lang.ClassCastException: com.centraalboekhuis.cbonline.model.VCboLookupArtFeViewRowImpl     at com.centraalboekhuis.cbonline.bestellen.ModelGetBestelTitelDetails.perform(ModelGetBestelTitelDetails.java:55)     at com.cumquatit.j2ee.controller.web.HttpController.doAction(HttpController.java:139)     at com.centraalboekhuis.cbonline.CBOnline.doAction(CBOnline.java:124)     at com.cumquatit.j2ee.controller.web.HttpController.doPost(HttpController.java:163)     at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))     at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))     at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))     at com.evermind[Oracle9iAS (2.0.0.0) Containers for J2EE].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java(Compiled Code))     at com.evermind[Oracle9iAS (2.0.0.0) Containers for J2EE].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java(Compiled Code))     at com.evermind[Oracle9iAS (2.0.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java(Compiled Code))     at com.evermind[Oracle9iAS (2.0.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java(Compiled Code))     at com.evermind[Oracle9iAS (2.0.0.0) Containers for J2EE].util.ThreadPoolThread.run(ThreadPoolThread.java(Compiled Code))
    Thanks

  • ClassCastException when accessing others app ejb

    Hi,
    I have the following problem:
    I use OC4J 9.0.2.0.0.
    I have a stateless SessionBean BeanA deployed in application AppA.
    I have a stateless SessionBean BeanB deployed in application AppB.
    I have a servlet ServletC deployed in application AppC.
    All 3 applications are deployed to the same oc4j instance.
    ServletC needs BeanA and BeanB.
    When ServletC tries to access one of the 2 ejbs a ClassCastException is thrown when the PortableRemoteObject.narrow() should be done.
    In the forum I found some hints using the parent attribute in the application tag of the server.xml file.
    But this only works for a client only using one other application but I have 2.
    Thanks for your help
    Guenther

    Hi Debabrata,
    I use the com.evermind.server.rmi.RMIInitialContextFactory.
    I think it is no good idea to have a chain of parents.
    I lose the separate class loaders.
    I cannot use different versions of libraries.
    There must exist a better solution than chaining applications with the parent attribute.
    Thanks
    Guenther

  • [BUG] ClassCastException when defining custom EventDispatcher

    Hi,
    The contextual event framework uses direct implementation class in its code, resulting in a ClassCastException being thrown when you define a custom EventDispatcher within the DataBindings.cpx file. The exception looks like:
    java.lang.ClassCastException: com.dmr.test.view.history.NavigationHistoryEventDispatcher cannot be cast to oracle.adf.model.binding.events.EventDispatcherImpl
         at oracle.adf.model.binding.DCBindingContainer.createEventDispatcherInstance(DCBindingContainer.java:4579)
         at oracle.adf.model.binding.DCBindingContainer.getEventDispatcher(DCBindingContainer.java:4617)The easy workaround is to extends EventDispatcherImpl, but it's quite annoying.
    Thanks,
    ~ Simon

    Simon,
    will file this as abug
    Frank

Maybe you are looking for