cancel
Showing results for 
Search instead for 
Did you mean: 

Assert statement

Former Member
0 Kudos

Hi,

i am developing on jdk 1.4.2_8 and use assert statements to ensure that e.g. references are not null:

Object test = null;

try {

assert test != null;

test.doSomething();

} catch (AssertionError error) {

//do something

}

The problem is that the assert - which is highlighted as keyword in NWDI - does not throw an exception but goes on and the test.doSomething() throws a null-Pointer.

Do you have any clue why the assert does not work properly?

Thank you and best regards,

Daniel

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos
0 Kudos

Hi,

thank you! Well, excuse me when my question is stupid, but where can I ensure that assertions will be enabled in NWDI? I could not find a flag or something like that to enable assertions. Due to the fact that I am not doing something like java -ea how can I then ensure that assertions are enabled?

Thank you and best regards,

Daniel

Message was edited by: Daniel Ritter

Former Member
0 Kudos

You could check for it in the runtime parameters.

You can force it with the -D flag to the JVM.

Enjoy

0 Kudos

Hi,

thank you all. Well, it seems to me that asserts can only be used in Java classes not within Java WD.

Best regards,

Daniel

Former Member
0 Kudos

Daniel,

And what is "Java WD" if it is not "Java classes"?

F.J. gives you correct answer.

However, I would like to emphasize your misuse of assertion functionality: Java program should not depend on the fact whether or not assertions are enabled. Obviously, you do right the opposite.

If your argument may be null, then it is better to check it via "if" statement and branch logic. If it must be non-null, then there is no reason to catch AssertionError.

Btw, do you know that you must not catch sublasses of java.lang.Error? Unless you are writting something like app. server or profiler.

VS

0 Kudos

Valery,

thank you for your unfriendly, unqualified and subjective answer. People who have the time to write stuff like that...

If you don't know what Java WD is then read the documentation. Furthermore you will see how to start it and then try to do it with assertions enabled.

Well, let me emphasize your thoughtlessness because you have no clue what I want to do with assertions!!! So don't judge people when you don't have any knowledge!

Btw, see above!

DR

Former Member
0 Kudos

LOL!

<i>thank you for your unfriendly, unqualified and subjective answer.</i>

"unfriendly" -- this is really "subjective"

"unqualified" -- well, who knows... every SDN member has business card, you may check my...

<i>People who have the time to write stuff like that...</i>

Yes, and some of these people even have time to check their own suggestions before post. Like me, for example...

<i>If you don't know what Java WD is then read the documentation.</i>

Thanks for the tip.

<i>Furthermore you will see how to start it and then try to do it with assertions enabled.</i>

Ok, Master. Verify my steps, please:

1. Run config tool

2. Go to cluster-data/instance_ID######/server_ID####

3. Add option on "General" tab, "Java parameters"

4. Restart server

I do not know what I do wrong, but assertions get enabled!

<i>Well, let me emphasize your thoughtlessness because you have no clue what I want to do with assertions!!! So don't judge people when you don't have any knowledge!</i>

Simply brilliant!!! No further comments...

0 Kudos

Dito!

Well, after all your funny statements I maybe now have the information that I wanted to have.

Please note that being impolite is only one way in treating people.

Best regards,

Daniel

former_member182372
Active Contributor
0 Kudos

1K club memeber <i>don't have any knowledge</i> ! ... ROFL...