Weird Runtime Issue

Hey experts,

  Upon calling a method of a class (from another class), the program is suddenly exiting, and I am getting this weird debug output:

Method............: f655a8 'PTT_J2ME/My_Message.problem_func (virtual)'
Stack Chunk.......: ef47f8
Frame Pointer.....: ef48c8
Current IP........: f6543e = f65428 + offset 22
Previous Frame....: ef489c
Previous IP.......: f66c0b (offset 1707)
Frame size........: 5 (2 arguments, 3 local variables)
Argument[0].......: ef46d8
Argument[1].......: ef4670
Local[2]..........: f64d48
Local[3]..........: f66c00
Local[4]..........: f64d60
Method............: f67480 'PTT_J2ME/VmailRecorder.commandAction (virtual)'
Stack Chunk.......: ef47f8
Frame Pointer.....: ef489c
Current IP........: f66c0b = f66560 + offset 1707
Previous Frame....: ef4840
Previous IP.......: f65934 (offset 220)
Frame size........: 17 (3 arguments, 14 local variables)
Argument[0].......: ef4058
Argument[1].......: ef3da0
Argument[2].......: ef28ec
Local[3]..........: ef46ec
Local[4]..........: ef46d8
Local[5]..........: f64ca4
Local[6]..........: 0
Local[7]..........: a
Local[8]..........: ff
Local[9]..........: 0
Local[10]..........: 1
Local[11]..........: 126
Local[12]..........: f64d08
Local[13]..........: 1012a603
Local[14]..........: f64d1c
Local[15]..........: 100d4664
Local[16]..........: f64ca4
Method............: f659ec 'PTT_J2ME/VmailRecorder$LoginThread.performLogin (virtual)'
Stack Chunk.......: ef47f8
Frame Pointer.....: ef4840
Current IP........: f65934 = f65858 + offset 220
Previous Frame....: ef4810
Previous IP.......: f65990 (offset 56)
Frame size........: 6 (1 arguments, 5 local variables)
Argument[0].......: ef4ac4
Local[1]..........: ef4794
Local[2]..........: a
Local[3]..........: ef46f8
Local[4]..........: 62
Local[5]..........: f62610
Method............: f659cc 'PTT_J2ME/VmailRecorder$LoginThread.run (virtual)'
Stack Chunk.......: ef47f8
Frame Pointer.....: ef4810
Current IP........: f65990 = f65958 + offset 56
Previous Frame....: 0
Previous IP.......: 1
Frame size........: 4 (1 arguments, 3 local variables)
Argument[0].......: ef4ac4
Local[1]..........: ef4058
Local[2]..........: 0
Local[3]..........: 0
VM status:
Instruction pointer.: f6543e (offset within invoking method: 22)
Next instruction....: 0xbb
Frame pointer.......: ef48c8
Local pointer.......: ef48b4
Stack size..........: 128; sp: ef48dc; ranges: ef4800-ef4a00;
Contents of the current stack frame:
    ef48b4: ef46d8 (lp)
    ef48b8: ef4670
    ef48bc: f64d48
    ef48c0: f66c00
    ef48c4: f64d60
    ef48c8: ef489c (fp)
    ef48cc: f66c0b
    ef48d0: ef48b0
    ef48d4: f655a8
    ef48d8: ef47f8
    ef48dc: 0 (end of frame) (sp)
Execution stack contains 224 items:
ef4ac4  
ef4058  
0  
0  
0  
1  
f64ca8  
f659cc  
ef47f8  
0  
ef4ac4  
ef4794  
a  
ef46f8  
62  
f62610  
ef4810  
f65990  
ef4824  
f659ec  
ef47f8  
0  
ef4058  
ef3da0  
ef28ec  
ef46ec  
ef46d8  
f64ca4  
0  
a  
ff  
0  
1  
126  
f64d08  
1012a603  
f64d1c  
100d4664  
f64ca4  
ef4840  
f65934  
ef4854  
f67480  
ef47f8  
0  
ef46d8  
ef4670  
f64d48  
f66c00  
f64d60  
ef489c  
f66c0b  
ef48b0  
f655a8  
ef47f8  
0  
Execution completed.
513289 bytecodes executed
59 thread switches
493 classes in the system (including system classes)
3555 dynamic objects allocated (122680 bytes)
10 garbage collections (103400 bytes collected)
Execution completed.
513289 bytecodes executed
59 thread switches
493 classes in the system (including system classes)
3555 dynamic objects allocated (122680 bytes)
10 garbage collections (103400 bytes collected)
Error verifying method PTT_J2ME/StringVector <init>(Ljava/lang/String;C)V
Approximate bytecode offset 23: Inconsistent or missing stackmap at target
ALERT: java/lang/VerifyError: PTT_J2ME/StringVector.


The code on which this is happening is in class Vmail_Recorder, it is as follows:
My_Message mes = new My_Message();
mes.problem_func(str_prob);

The problem is happening upon a call to the method problem_func of class My_Message.


any help on solving this issue??
LVL 3
mte01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSr. Software engineerCommented:
>> The problem is happening upon a call to the method problem_func of class My_Message.
Code of the one?
zzynxSr. Software engineerCommented:
I meant "Code of that one?"
zzynxSr. Software engineerCommented:
So, if possible post your My_Message class
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

mte01Author Commented:
>>Code of that one?

Yes, at the 2nd line of the code in the question, the problem is occuring. This is the code of problem_func:

public void problem_func(String s)
{
        if(s.indexOf('d')!=-1)
            s = s.substring(0,s.indexOf('d'));
}

Upon emptying this function, the problem is not happening, and upon writing some code inside it, sometimes the problem happens, sometimes it doesn't in a very weird manner!!!
mte01Author Commented:
The code of My_Message class:


package PTT_J2ME;

import java.util.*;


public class My_Message
{
    private int code;
    private Vector fields;
   
    public My_Message()
    {
        code = 0;
        fields = new Vector();
    }
   
    public void setcode(int c)
    {
        code = c;
    }
   
    public void setfields(Vector f)
    {
        fields = f;
    }
   
    public int getcode()
    {
        return code;
    }
   
    public Vector getfields()
    {
        return fields;
    }
   
    public void problem_func(String s)
    {
        if(s.indexOf('d')!=-1)
            s = s.substring(0,s.indexOf('d'));
    }
}
zzynxSr. Software engineerCommented:
Remark:
Since
- String is an immutable object,
- I guess you want to change the input string
I think your problem_func should be:

    public String problem_func(String s) {
        String result = s;
        if(s.indexOf('d')!=-1)
            result = s.substring(0, s.indexOf('d'));
        return result;
    }

and your code
>> My_Message mes = new My_Message();
>> mes.problem_func(str_prob);

should be

My_Message mes = new My_Message();
str_prob = mes.problem_func(str_prob);
mte01Author Commented:
The code which I just showed you in problem_func is just a section of a longer code that was the original and that was also causing a problem, so I removed most of it, and kept those two lines that were still causing a problem........
CEHJCommented:
You could also do


public void problem_func(StringBuffer s)
{
      while (sb.indexOf("d") > -1)
      {
            sb.deleteCharAt(sb.length() -1);
      }
}

which would be less expensive and would require a smaller change to your application logic
mte01Author Commented:
>>zzynex, CEHJ

This was just anything that I wrote inside this function that made the problem happen......the actual function is not like this., but this is a minimal code that is causing the problem.....and I've tried the code that you wrote and it's still causing the same problem......

This is the actual function:

public void problem_func(String s)
{
        if(s.indexOf('\0')!=-1)
            s = s.substring(0,s.indexOf('\0'));
        StringVector v1 = new StringVector(s,'|');
        if(v1.size()>3)
            throw new IllegalArgumentException("Wrong Message String");
        code = Integer.parseInt(v1.elementAt(0).toString());
        for(int i=1;i<v1.size();i++)
        {
            StringVector v2 = new StringVector(v1.elementAt(i).toString(),':');
            fields.addElement(v2);
        }
 }


and there are also more functions in the class My_Message, but I removed them to try to see where the problem is coming from......
zzynxSr. Software engineerCommented:
>> and kept those two lines that were still causing a problem
Do you have problem when you just do something basic as:

public void problem_func(String s) {
     System.out.println(s);
}

>> public void problem_func(StringBuffer s)  
the input parameter should be called 'sb'
I guess ;°)
mte01Author Commented:
>>public void problem_func(String s) throws IllegalArgumentException
    {

as a correction
mte01Author Commented:
>>Do you have problem when you just do something basic as

No with just this statement, it's running successfully.
zzynxSr. Software engineerCommented:
>> No with just this statement, it's running successfully.
Indicating that your statement must be wrong somewhere...
mte01Author Commented:
>>zzynx

with something like Vector v = new Vector(); only inside it, it is casuing this problem....
zzynxSr. Software engineerCommented:
Does this give problems:

public void problem_func(String s) {
     if (s==null)
         System.out.println("Null!!!");
     else if(s.indexOf('d')!=-1)
         System.out.println( s.substring(0, s.indexOf('d')) );
     else
         System.out.println(s);
}

Or this:

public void problem_func(String s) {
        if (s==null)
            return;
        if(s.indexOf('\0')!=-1)
            s = s.substring(0,s.indexOf('\0'));
}
zzynxSr. Software engineerCommented:
>> with something like Vector v = new Vector(); only inside it, it is casuing this problem....
????
The original stripped down version didn't have that and nevertheless it failed...
mte01Author Commented:
Yes with your piece of code, it gave this problem.......It's a very weird runtime issue, I've been working with java for 2 years now, and I haven't seen soemthing like this, I can't predict where it's failing, and where it's not.
zzynxSr. Software engineerCommented:
Strange.
At which OS are you running?
How do you run your app?
And where do you get that debug output?
mte01Author Commented:
1- Windows XP SP2

2- On Sun One IDE, by chosing Execute as I normally do with any java program

3- On the std output with the System.out.println stuff
CEHJCommented:
You need to debug into that function. e.g. if the String starts with '\0' the code will produce a 0-length String
CEHJCommented:
What is StringVector btw?
mte01Author Commented:
The string is "1|Mohamad Majzoub".........as I expected it to be......I printed it.

zzynxSr. Software engineerCommented:
I meant where do you get that output:

Method............: f655a8 'PTT_J2ME/My_Message.problem_func (virtual)'
Stack Chunk.......: ef47f8
Frame Pointer.....: ef48c8
Current IP........: f6543e = f65428 + offset 22
Previous Frame....: ef489c
Previous IP.......: f66c0b (offset 1707)
Frame size........: 5 (2 arguments, 3 local variables)
Argument[0].......: ef46d8
zzynxSr. Software engineerCommented:
Although apparently not the solution of your problem,
safe programming requires your function to start with:

        if (s==null)
            return;
mte01Author Commented:
>>I meant where do you get that output

On the standard output
mte01Author Commented:
>>safe programming requires your function to start with

Ok....I added that.....
CEHJCommented:
You need to debug at a higher level - you're not intested in stack frames etc. ;-)
mte01Author Commented:
>>CEHJ

Ok....so what should I do???
CEHJCommented:
Debuggers are usually found in IDEs - can you not use one? Otherwise you need a lot of debug statements
mte01Author Commented:
Yes....I used the debugger, and stepped into the program (step by step), when I reach the position where the function is being called, the program is exiting....
zzynxSr. Software engineerCommented:
>> when I reach the position where the function is being called, the program is exiting....
- Try to jump inside the function (having only that println call)
- Try to jump inside the function having the normal code
CEHJCommented:
You didn't tell me (post code) what StringVector is ...
zzynxSr. Software engineerCommented:
Let me guess: a Vector containing String objects?
;°)
mte01Author Commented:
>>zzynx

Stepping into that function call using the println only inside it occurs normally
Stepping into (and not over) that function call causes the program to exit.

>>CEHJ
Yes, StringVector is a Vector containing strings, but I am sure it has nothing to do with the problem because using Vector alone is causing the problem.
zzynxSr. Software engineerCommented:
>> Stepping into (and not over) that function call causes the program to exit.
Never seen/heard such a strange thing.
Sorry... :°(
mte01Author Commented:
>>Never seen/heard such a strange thing

Me, too....do you want me to send you the files, so you could try them. The client program is a 3 files (2 classes & 1 main class), and the server is 1 file (1 class & 1 main class).
CEHJCommented:
I'll try it if you post a public, working, jar
mte01Author Commented:
What do you mean a public, working, jar??? I'll be sending you the source files.....
CEHJCommented:
I mean post a public *link* to a jar
mte01Author Commented:
ah okk, I don't think it would work this way, because you have to run the server progam alone, and then the client should connect to it.

One more important thing (which I should have mentioned in this question), but I didn't mention becuase it usually scares experts away....the client program is in J2ME

If you still want me to send you the source files of the client and the server please tell me.
CEHJCommented:
>>.the client program is in J2ME

I know that ;-)
zzynxSr. Software engineerCommented:
>> The code of My_Message class:
>> package PTT_J2ME;
;°)
CEHJCommented:
Having said that, it would be better if i could run it and at the moment, i don't have the environment. Try it on some other VM if you can
zzynxSr. Software engineerCommented:
>> i don't have the environment
Same for me. Sorry.
mte01Author Commented:
It's OK guys.........problem solved, and guess how......I ran it on NetBeans IDE (instead of Sun OneIDE), and the program didn't crash......I am going to use NetBeans from now on.
zzynxSr. Software engineerCommented:
>> It's OK guys.........problem solved
Good to hear.

>> I am going to use NetBeans from now on
I use for two years now and I'm quite happy with it.

What do you plan to do with this question?

If you to close it by awarding some comments, that's OK.
If you want to delete this question, you can post a zero-point question in http://www.experts-exchange.com/Community_Support/

Subject: Moderator Please Delete
Body: Please delete this question:
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21480217.html
LunchyCommented:
Closed, 500 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.