Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 661387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:15:41+00:00 2026-05-13T23:15:41+00:00

Given this piece of code : public static void writeFile(File file,List buffer)throws IOException{ File

  • 0

Given this piece of code :

public static void writeFile(File file,List buffer)throws IOException{
    File fic = new File(file.getCanonicalPath());
    cat.debug("writing file : "+fic.getAbsolutePath());
    FileOutputStream out = new FileOutputStream(fic);
    PrintStream ps = new PrintStream(out);
    for(int i=0;i<buffer.size();i++){
        ps.println(buffer.get(i));
    }
    ps.flush();
    ps.close();
    out.close();
}

(please no advice about how to close streams safely, this is legacy code and the new version makes use of try / finally)

I get a ClassCastException at the “ps.println(buffer.get(i))”

this method is called several times (say 5 times) with a list only filled with Strings
then, it is called with a list filled with String and an other object (say ErrorObject)
At the point we reach the 1st ErrorObject, we get the ClassCastException.

com.mycompany.ErrorObject incompatible with java.lang.String

This problem occurs in production environment, but cannot be reproduced in Dev environment :
Prod : jvm=IBM J9 VM 2.4 J2RE 1.6.0 IBM J9 2.4 AIX ppc-32 jvmap3260-20081105_25433 (JIT enabled, AOT enabled)
Dev : WinXP, JDK 1.6.0_16

Is there any reason this code could fail ?

It was patched recently, i fear that the production team did not upgrade the jar correctly, but my boss already checked that the patch was applied correclty …

I was wondering if the Just in Time compiler could “wire” the ps.println to the ps.println(String) instead of the ps.println(Object).
That could explain such a problem, but I have no idea if this possible.

Any advices welcome, thank you in advance

EDIT :
i was asked full stack trace so here it is :

java.lang.ClassCastException: com.mycompany.util.ErrorObject incompatible with java.lang.String
    at com.mycompany.util.FileUtils.writeFile(FileUtils.java:91)
    at com.mycompany.util.FileUtils.writeFile(FileUtils.java:50)
    at com.mycompany.itools.task.DBCompareInits.doDBTask(DBCompareInits.java:959)
    at com.mycompany.itools.task.DBTask.doTask(DBTask.java:115)
    at com.mycompany.itools.task.TaskGroup.startGroup(TaskGroup.java:115)
    at com.mycompany.runner.Runner.main(Runner.java:209)

EDIT 2 :
javap -c

   65:  invokeinterface #20,  1; //InterfaceMethod java/util/List.size:()I
   70:  if_icmpge   92
   73:  aload   4
   75:  aload_1
   76:  iload   5
   78:  invokeinterface #21,  2; //InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
   83:  invokevirtual   #31; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V
   86:  iinc    5, 1
   89:  goto    62
   92:  aload   4
   94:  invokevirtual   #32; //Method java/io/PrintStream.flush:()V
   97:  aload   4
   99:  invokevirtual   #33; //Method java/io/PrintStream.close:()V
   102: aload_3
   103: invokevirtual   #28; //Method java/io/FileOutputStream.close:()V
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:15:41+00:00Added an answer on May 13, 2026 at 11:15 pm

    I was wondering if the Just in Time compiler could “wire” the ps.println to the ps.println(String) instead of the ps.println(Object). That could explain such a problem, but I have no idea if this possible.

    It is not possible. Or at least not unless there is a bytecode compiler or JIT compiler bug. And you should only blame compiler bugs if you have irrefutable evidence that this is so.

    However, the first thing I would check is that the code being executed was really compiled from the source code that you are looking at. One way to confirm this would be to recompile from source, and then compare the results of running javap on respective copies of the class. Looking at the bytecodes will also tell you which overload of println the bytecode compiler is saying to use.

    EDIT – the javap output clearly shows that that version of the bytecode should call println(Object), and there is no checkcast opcode in sight. A JIT compiler bug that calls the wrong method and spontaneously inserts code to do a classcast is sounding more and more implausible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 392k
  • Answers 392k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If session[:user_id] is '3' and params[:user_id] is '3' and they… May 15, 2026 at 1:49 am
  • Editorial Team
    Editorial Team added an answer For this you need to use LinkedIn API. May 15, 2026 at 1:49 am
  • Editorial Team
    Editorial Team added an answer I gave up trying to fix and resorted the classic… May 15, 2026 at 1:49 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.