Wierd problem

Hi All,

I've been facing a very wierd problem.

I have two classes, A & B under the same package XYZ.

A has a method, a(); and B has a method b(), which calls a().

A is a singleton class.

What's wierd is that for some unknown reason I can't get to the current instance of A, from B's b() and get an Exception which shouldn't even be occuring (since those parts of a() aren't reached during execution)!

And when I can the same bit of code from A's main method, it works!

This is what I mean..

publicclass A

{privatestatic A instance;

//Returns the current instance of this class

publicstatic A getInstance()

{if(instance==null)

instance =new A();

return instance;

}

publicvoid a()

{ System.out.println ("Inside a()");

//..

//Some operations..

//..then..

if(someVeryRareCondition)

thrownew ExceptionA(reasonOfExceptionString)

}//end-of-a()-method

publicstaticvoid Main(String[] args)

{ A.getInstance().a();//<--This works, prints the String "Inside a()"

}

}//end-of-class A

publicclass B

{public b()

{ A.getInstance().a();//<--This does NOT work, get the ExceptionA

}

}//end-of-classB

Infact, even ifb() looked like :

public b()

{ A objA = A.getInstance();//--(pt.A)

objA .a();//--(pt.B)

}

before it reached (pt.A), I'm getting the above mentioned Exception..

There's no other class where such an Exception is ever thrown or caught.

[ExceptionA belongs to the same package XYZ].

Any comments would be greatly appreciated.

Thanks in advance.

Nirmalya

[3227 byte] By [imNirmalyaa] at [2007-9-28 19:12:01]
# 1

"What's wierd is that for some unknown reason I can't get to the current instance of A"

Are you sure you don't? If so, you should get a NullPointerException on A.getInstance().a();

It seems that you actually get the instance and that "someVeryRareCondition" is true.

/Stephane

spenhoeta at 2007-7-12 17:37:56 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

> "What's wierd is that for some unknown reason I

> can't get to the current instance of A"

>

> Are you sure you don't? If so, you should get a

> NullPointerException on A.getInstance().a();

> It seems that you actually get the instance and that

> "someVeryRareCondition" is true.

>

> /Stephane

Hi Stephane,

I stepped thru the debugger.

In the code,

public b()

{ A objA = A.getInstance(); //--(pt.A)

objA .a(); //--(pt.B)

}

I wasn't even able to reach A's getInstance() method at pt.A.

To briefly explain what I am trying to do:

I am writing a plugin for Eclipse.

Class A calls some code in some packages in some external JAR files (no problems faced in using those JAR files). The exception I mentioned (ExceptionA) happens under some very rare conditions.. so its really very wierd for Eclipse giving me that exception.. when I am just trying to get A's instance (at pt.A) which does not even call those 3rd party packages.

Any sugegstions would be greatly appreciated..

Thanks & Regards,

Nirmalya

imNirmalyaa at 2007-7-12 17:37:56 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

Sorry for these "naive" questions :

- have you, somewhere, another class with the name "A". I already had a similar problem when using the wrong class, imported by an "import something.*"

- what do you mean by "I wasn't even able to reach A's getInstance() method at pt.A.".

- is "someVeryRareCondition" set in a catch block or something?

/Stephane

spenhoeta at 2007-7-12 17:37:56 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4

Hi,

Thanks once again for your reply.

To answer your questions in the sequence asked:

[1] I rechecked.. there are no other classes bearing the same name (not in my packages, or Eclipse's, nor in the 3rd party packages).

[2] In the line A objA = A.getInstance(); (inside public b()), even if I had a dummy println stmt just before it, then during execution, it'll print whatever is in that dummy println stmt, then just throw me that ExceptionA (it does not enter A's getInstance() method).

[3] Yes, the "someVeryRareCondition" is set in a catch block.

Somebody suggested that we may be getting the exception from somewhere else (such as another thread/method etc..).. We reconfirmed that that wasn't the case as its a single-threaded application.

Thanks & Regards,

Nirmalya

BTW: The questions weren't naive :)

imNirmalyaa at 2007-7-12 17:37:56 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5
[1] OK.[2] Is getInstance() overriden in class B? Could you post the first few lines of your ExceptionA's stack trace() as well?[3] What kind of exception do you catch? We never know : it can give us a clue about what's happening./Stephane
spenhoeta at 2007-7-12 17:37:56 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 6
Anything new with your problem?By the way, I went to your web site. Some of the photos you've taken are great... Do you intend to let visitors zoom on them, they're just a bit too small!/Stephane
spenhoeta at 2007-7-12 17:37:56 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...