Placing tests in java.lang package (for testing protected methods)

Alan Bateman Alan.Bateman at oracle.com
Tue May 26 09:27:23 UTC 2015



On 26/05/2015 10:04, Tomasz Kowalczewski wrote:
> Hi,
>
> I am trying to test a protected method of java.lang.String. Is this 
> possible with jtreg? If I specify:
>
> * @run testng java.lang.StringIndexOfCharSequenceTest
> */
> package java.lang;
>
> I will (unsurprisingly) get "SecurityException: Prohibited package 
> name: java.lang". I was thinking that there may be some jtreg magic to 
> circumvent this?
>
Protected or package private? I assume the latter, in which case the 
test class will need to be in java.lang with the boot loader as the 
defining loader. Outside of the test harness then you could do this with 
-Xbootclasspath/a.

As a jtreg test then the magic property to add to TEST.properties is 
bootclasspath.dirs to specify the directory with the classes to be 
loaded by the boot loader. Jon or others might have more to say on this 
but I think this feature is somewhat limited to TestNG tests, I don't 
think I've seen it used for anything other than TestNG tests. You'll see 
examples in the jdk repo, specifically in jdk/test/java/util/stream.

-Alan


More information about the jtreg-use mailing list