title: Getting ClassCastException in java
body: <p>Hi I am getting the following exception</p>
  
  <p>Exception in thread "main" java.lang.ClassCastException: javax.mail.util.SharedByteArrayInputStream cannot be cast to javax.mail.Multipart</p>
  
  <p>I am not getting any compilation exception in Eclipse IDE, but when I am trying build the project I am getting this exception.</p>
  
  <p>After building the project, I am running the project through java -jar, so its not satisfying the if(content instanceof Multipart) condition, but when i am running from the Eclipse IDE its working fine. Any pointers will greatly helpful to me</p>
  
  <p>From the eclipse IDE I'm getting the megssage.getContent() as javax.mail.internet.MimeMultipart@1dc0e7a
  but when running using the jar file  I'm getting the content as
  javax.mail.util.SharedByteArrayInputStream@2f0d54</p>
  
  <p>Please can you tell me what is the difference between them.</p>
  
  <p>Modified code is:</p>
  
  <pre><code> InputStream inStream = null;
      if(!message.getContentType().contains("text/plain")){
          Object content = message.getContent();          
          if (message.isMimeType("multipart/*")) {  
              //message.isMimeType("multipart/*")||
              Multipart multipart = (Multipart) content;
              for (int j = 0; j &lt; multipart.getCount(); j++) {
                  BodyPart bodyPart = multipart.getBodyPart(j);
                  inStream = bodyPart.getInputStream();
                  fileName=bodyPart.getFileName();
                  } 
          }
          else{
          System.out.println("content not instance of multipart");    
          }`enter code here`  
  </code></pre>
  
  <p>Please can anyone help me out in solving this issue..</p>
  
  <p>Thanks in advance...</p>