• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

enabling assertions switches

 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

>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 ]
 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic