This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enabling assertions switches Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enabling assertions switches" Watch "enabling assertions switches" New topic
Author

enabling assertions switches

Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391

>java -ea:com... -da:com.dan... com.dan.chisholm.MyClass
>java -ea:com.dan... -da:com... com.dan.chisholm.MyClass
Exception in thread "main" java.lang.AssertionError
>java -da:com... -ea:com.dan... com.dan.chisholm.MyClass
Exception in thread "main" java.lang.AssertionError
>java -da:com.dan... -ea:com... com.dan.chisholm.MyClass
Since the switches are processed in order, I expected the second switch to override the first switch. But that is not what happens.
[ June 15, 2003: Message edited by: Marlene Miller ]
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
The output on my machine (java 1.4.1_02, Linux kernel 2.4) is consistent:
$java -ea -da -> No assertion error
$java -da -ea -> assertion error
What version of Java are you using?
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
I tried the Marlene code and the output was as that of Marlene. Assertions are only available in the JDK 1.4. I have JDK 1.4. To be precise
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
Which makes me think that assertions are only enabled for a package and not for a subpackage, unless explictly done.
[ June 15, 2003: Message edited by: Anupam Sinha ]
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Thank you very much Alton and Anupam for trying my examples on your systems and reporting your results.
Alton, I am using 1.4.1_01 on Windows 2K. Maybe I should upgrade to 02.
C:\>java -version
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
Anumpam, the spec says :<package name>�...� applies to the specific package and to any subpackages.
Regarding my second and fourth examples,
>java -ea:com.dan... -da:com... com.dan.chisholm.MyClass
Exception in thread "main" java.lang.AssertionError
>java -da:com.dan... -ea:com... com.dan.chisholm.MyClass
I *expected* the second switch with the more general package com to override the first switch with the more specific subpackage com.dan, because they say the switches are *processed in order*.
I have figured out a way to explain the results, which I hope generalizes correctly: Visualize or draw the directory hierarchy (com\dan\chisholm\MyClass). *Mark* each directory or file *enabled* or *disabled* according to the switches. When you are done, a mark in a lower directory overrides a mark in a higher directory.
[ June 15, 2003: Message edited by: Marlene Miller ]
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Marlene
I was aware that
the spec says :<package name>“...” applies to the specific package and to any subpackages.

But after seeing your code I thought it might not always happen that way.
When you are done, a mark in a lower directory overrides a mark in a higher directory.

This is what I meant when I said
Which makes me think that assertions are only enabled for a package and not for a subpackage, unless explictly done.

But this means that either the order in which assertions command line arguments are processed is not always ordered(which is less likely) or it means that enabling assertions for a pcakage does not neccessarily enables assertions in the subpackage.
But one thing that I found out after re-reading the first post is that the more specific path overrides the more general one. That is
java -ea:com... -da:com.dan... com.dan.chisholm.MyClass
java -ea:com.dan... -da:com... com.dan.chisholm.MyClass
Exception in thread "main" java.lang.AssertionError
java -da:com... -ea:com.dan... com.dan.chisholm.MyClass
Exception in thread "main" java.lang.AssertionError
java -da:com.dan... -ea:com... com.dan.chisholm.MyClass
In the above line the bold line are more specific and are the ones according to whom the output is determined.
So basically if you enable and disable for the same path(package hierarchy) the order of processing would be the same, for second and the thrid command line replace them with this
java -ea:com.dan... -da:com.dan... com.dan.chisholm.MyClass
java -da:com.com... -ea:com.dan... com.dan.chisholm.MyClass
and you should know the difference.
The point is the more specific path rules.
[ June 15, 2003: Message edited by: Anupam Sinha ]
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
I agree, Anupam. That's the way it looks to me, too.
Now we have to understand why Alton, with version 1.4.1_02 on Linux, gets different results. So far I haven't found any bug reports.
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
Originally posted by Marlene Miller:
I agree, Anupam. That's the way it looks to me, too.
Now we have to understand why Alton, with version 1.4.1_02 on Linux, gets different results. So far I haven't found any bug reports.

Pls. ignore my earlier post. I wasn't paying much attention to the subpackages. I thought that you were just checking the position of the switches.
Anyway, after re-testing the actual case, I got the same output.
I got this from my java man file:

To run a program with assertions enabled in package com.wombat.fruitbat but disabled in class com.wom� bat.fruitbat.Brickbat, the following command could be used:
java -ea:com.wombat.fruitbat... -da:com.wombat.fruitbat.Brickbat <Main Class>

Although this paragraph is under the -da switch, I think it works both ways.
[ June 15, 2003: Message edited by: Alton Hernandez ]
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Thank you Alton for reviewing your results and letting me know. Now I won't download 1.4.1_03. That's good news.
All of the examples I have seen of the use of multiple switches show the more general directory followed by the more specfic directory or file. No one talks about the reverse order.
[ June 15, 2003: Message edited by: Marlene Miller ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: enabling assertions switches
 
Similar Threads
doubt :assertion errors
About Exception and Throwable
Question on assertion
Enable assertions in current package.
Regarding assertion