Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » -> IllegalAccessError using JUnit PDE Test
-> IllegalAccessError using JUnit PDE Test [message #86363] Tue, 19 August 2003 05:09 Go to next message
Eclipse UserFriend
Hi there,

I have split a project containing JUnit tests. I wanted to seperate
the ui and related tests. Now I ran into this error message.

java.lang.IllegalAccessError: tried to access method
BeanItem.propertyChanged
(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V from class
BeanItem

Normally I ran all tests which doesn't require a ui using the normal JUnit
launcher.
But using the PDE JUnit launcher (launch the test within a seperated Eclipse
workspace) causes an IllegalAccessError.

The fun is, it finds the classes but calling a method fails for sure.

For example the above things work:
new BeanItem(0,0);

new BeanItemImpl extends BeanItem {
}

BeanItemImpl bean=new BeanItemImpl(0,0);
bean.propertyChanged(...);

but if i use

BeanItem bean=new BeanItem(0,0);
bean.propertyChanged(...);

it fails cause of IllegalAccessError...


Does someone has a clue? (plugin dependencies are correct because
the class is found and it can be instanciated.


Thanks

Martin(Kersten)
Re: -> IllegalAccessError using JUnit PDE Test [message #86727 is a reply to message #86363] Tue, 19 August 2003 18:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Kevin.clark.accessbc.com.nospam

These errors generally mean you are trying to access a method that you do
not have access to. In other words, are you calling a private or protected
method/class/variable? If so, change the security level to public... Or
create appropriate public API.



Martin Kersten wrote:

> Hi there,

> I have split a project containing JUnit tests. I wanted to seperate
> the ui and related tests. Now I ran into this error message.

> java.lang.IllegalAccessError: tried to access method
> BeanItem.propertyChanged
> (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V from class
> BeanItem

> Normally I ran all tests which doesn't require a ui using the normal JUnit
> launcher.
> But using the PDE JUnit launcher (launch the test within a seperated Eclipse
> workspace) causes an IllegalAccessError.

> The fun is, it finds the classes but calling a method fails for sure.

> For example the above things work:
> new BeanItem(0,0);

> new BeanItemImpl extends BeanItem {
> }

> BeanItemImpl bean=new BeanItemImpl(0,0);
> bean.propertyChanged(...);

> but if i use

> BeanItem bean=new BeanItem(0,0);
> bean.propertyChanged(...);

> it fails cause of IllegalAccessError...


> Does someone has a clue? (plugin dependencies are correct because
> the class is found and it can be instanciated.


> Thanks

> Martin(Kersten)
Re: -> IllegalAccessError using JUnit PDE Test [message #86882 is a reply to message #86727] Wed, 20 August 2003 02:31 Go to previous messageGo to next message
Eclipse UserFriend
> These errors generally mean you are trying to access a method that you do
> not have access to. In other words, are you calling a private or protected
> method/class/variable? If so, change the security level to public... Or
> create appropriate public API.

I checked that. The problem is, its working if you use the normal JUnit
launcher. But testing it using a seperate Workbench (JUnit PDE) fails.

Indeed it is the access level but not the way you might think. Here is
what goes wrong.

The plugins are running within their own area. Everything outside that
area is threaten as foreign. Therefore if you seperate a package into
fragments which are spread over diffrent plugins you are running into
the problem I am facing.

Take this as an example:

//plugin containing production code
package myPackage;

public class A {
private privateMethod() {}
protected protectedMethod() {}
defaultMethod() {}
public publicMethod() {}
}

//plugin containing test code
package myPackage;
public class TestA extends TestCase {
public void testPrivateMethod() {
new A().privateMethod(); //fails because private is not visible
}
public void testProtectedMethod() {
new A().protectedMethod(); //visible
}
public void testDefaultMethod() {
new A().defaultMethod(); //visible
}
public void testPublicMethod() {
new A().publicMethod(); //visible
}
}

The visiblilty changes if both plugins are
loaded as plugins. In this case default and protected
are not visibil. But running both fragments shared
between Projects and are included using a class path
it is visible.

There are two ways to get around it.
1. Create your own implementation:
BeanItem item
BeanItemImpl item2 (BeanItemImpl simply extends BeanItem)
-> item.protected/defaultMethod fails
-> item2.protected/defaultMethod works
2. Seperate the test and production code by using two
seperate source directories but both directories contained
within the same plugin. (Maybe plugin fragment or within the
same project) -> Next think I am testing ;)


Well I guess this is the reason for PluginFraments ;)


Bye

Martin (Kersten)

>
>
>
> Martin Kersten wrote:
>
> > Hi there,
>
> > I have split a project containing JUnit tests. I wanted to seperate
> > the ui and related tests. Now I ran into this error message.
>
> > java.lang.IllegalAccessError: tried to access method
> > BeanItem.propertyChanged
> > (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V from class
> > BeanItem
>
> > Normally I ran all tests which doesn't require a ui using the normal
JUnit
> > launcher.
> > But using the PDE JUnit launcher (launch the test within a seperated
Eclipse
> > workspace) causes an IllegalAccessError.
>
> > The fun is, it finds the classes but calling a method fails for sure.
>
> > For example the above things work:
> > new BeanItem(0,0);
>
> > new BeanItemImpl extends BeanItem {
> > }
>
> > BeanItemImpl bean=new BeanItemImpl(0,0);
> > bean.propertyChanged(...);
>
> > but if i use
>
> > BeanItem bean=new BeanItem(0,0);
> > bean.propertyChanged(...);
>
> > it fails cause of IllegalAccessError...
>
>
> > Does someone has a clue? (plugin dependencies are correct because
> > the class is found and it can be instanciated.
>
>
> > Thanks
>
> > Martin(Kersten)
>
>
Re: -> IllegalAccessError using JUnit PDE Test [message #86898 is a reply to message #86882] Wed, 20 August 2003 02:50 Go to previous messageGo to next message
Eclipse UserFriend
> There are two ways to get around it.
> 1. Create your own implementation:
> BeanItem item
> BeanItemImpl item2 (BeanItemImpl simply extends BeanItem)
> -> item.protected/defaultMethod fails
> -> item2.protected/defaultMethod works
> 2. Seperate the test and production code by using two
> seperate source directories but both directories contained
> within the same plugin. (Maybe plugin fragment or within the
> same project) -> Next think I am testing ;)

What a pitty ... The JUnit PDE launcher keeps complaining that
the fragment cant be run cause it cant determinate the Plugin's id.

Whats that for? Looks like I should file a feature request?!

Ok I try first attempt first. The problem with it should be the
mixed up plugin.xml. I have to register the Viewparts of the
function tests.

Ok lets try this.


Martin (Kersten)

>
>
> Well I guess this is the reason for PluginFraments ;)
>
>
> Bye
>
> Martin (Kersten)
>
> >
> >
> >
> > Martin Kersten wrote:
> >
> > > Hi there,
> >
> > > I have split a project containing JUnit tests. I wanted to seperate
> > > the ui and related tests. Now I ran into this error message.
> >
> > > java.lang.IllegalAccessError: tried to access method
> > > BeanItem.propertyChanged
> > > (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V from class
> > > BeanItem
> >
> > > Normally I ran all tests which doesn't require a ui using the normal
> JUnit
> > > launcher.
> > > But using the PDE JUnit launcher (launch the test within a seperated
> Eclipse
> > > workspace) causes an IllegalAccessError.
> >
> > > The fun is, it finds the classes but calling a method fails for sure.
> >
> > > For example the above things work:
> > > new BeanItem(0,0);
> >
> > > new BeanItemImpl extends BeanItem {
> > > }
> >
> > > BeanItemImpl bean=new BeanItemImpl(0,0);
> > > bean.propertyChanged(...);
> >
> > > but if i use
> >
> > > BeanItem bean=new BeanItem(0,0);
> > > bean.propertyChanged(...);
> >
> > > it fails cause of IllegalAccessError...
> >
> >
> > > Does someone has a clue? (plugin dependencies are correct because
> > > the class is found and it can be instanciated.
> >
> >
> > > Thanks
> >
> > > Martin(Kersten)
> >
> >
>
>
Re: -> IllegalAccessError using JUnit PDE Test [message #86911 is a reply to message #86882] Wed, 20 August 2003 02:59 Go to previous message
Eclipse UserFriend
Looks like I forgot to mention the third way ;)

Seperate source directory into two. This way works excellent on a
creamy base ;).

Here is what I have done:
create a second directory called src-test. So every thing gets seperated
in the package/type view (viewing either the production code or the test
code)
and I have the full access of default and protected methods of classes
within the same package.

Drawback:
The plugin.xml gets additional sections about test views. I think I will
just
add a second section or even better include a plugin-test.xml file as part.

So to get a shippable version you have to remove the bin-test.jar and
a line/section in the plugin.xml.

Well if this isn't foxy, I don't know what else is... .


Martin (Kersten)


> > These errors generally mean you are trying to access a method that you
do
> > not have access to. In other words, are you calling a private or
protected
> > method/class/variable? If so, change the security level to public... Or
> > create appropriate public API.
>
> I checked that. The problem is, its working if you use the normal JUnit
> launcher. But testing it using a seperate Workbench (JUnit PDE) fails.
>
> Indeed it is the access level but not the way you might think. Here is
> what goes wrong.
>
> The plugins are running within their own area. Everything outside that
> area is threaten as foreign. Therefore if you seperate a package into
> fragments which are spread over diffrent plugins you are running into
> the problem I am facing.
>
> Take this as an example:
>
> //plugin containing production code
> package myPackage;
>
> public class A {
> private privateMethod() {}
> protected protectedMethod() {}
> defaultMethod() {}
> public publicMethod() {}
> }
>
> //plugin containing test code
> package myPackage;
> public class TestA extends TestCase {
> public void testPrivateMethod() {
> new A().privateMethod(); //fails because private is not
visible
> }
> public void testProtectedMethod() {
> new A().protectedMethod(); //visible
> }
> public void testDefaultMethod() {
> new A().defaultMethod(); //visible
> }
> public void testPublicMethod() {
> new A().publicMethod(); //visible
> }
> }
>
> The visiblilty changes if both plugins are
> loaded as plugins. In this case default and protected
> are not visibil. But running both fragments shared
> between Projects and are included using a class path
> it is visible.
>
> There are two ways to get around it.
> 1. Create your own implementation:
> BeanItem item
> BeanItemImpl item2 (BeanItemImpl simply extends BeanItem)
> -> item.protected/defaultMethod fails
> -> item2.protected/defaultMethod works
> 2. Seperate the test and production code by using two
> seperate source directories but both directories contained
> within the same plugin. (Maybe plugin fragment or within the
> same project) -> Next think I am testing ;)
>
>
> Well I guess this is the reason for PluginFraments ;)
>
>
> Bye
>
> Martin (Kersten)
>
> >
> >
> >
> > Martin Kersten wrote:
> >
> > > Hi there,
> >
> > > I have split a project containing JUnit tests. I wanted to seperate
> > > the ui and related tests. Now I ran into this error message.
> >
> > > java.lang.IllegalAccessError: tried to access method
> > > BeanItem.propertyChanged
> > > (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V from class
> > > BeanItem
> >
> > > Normally I ran all tests which doesn't require a ui using the normal
> JUnit
> > > launcher.
> > > But using the PDE JUnit launcher (launch the test within a seperated
> Eclipse
> > > workspace) causes an IllegalAccessError.
> >
> > > The fun is, it finds the classes but calling a method fails for sure.
> >
> > > For example the above things work:
> > > new BeanItem(0,0);
> >
> > > new BeanItemImpl extends BeanItem {
> > > }
> >
> > > BeanItemImpl bean=new BeanItemImpl(0,0);
> > > bean.propertyChanged(...);
> >
> > > but if i use
> >
> > > BeanItem bean=new BeanItem(0,0);
> > > bean.propertyChanged(...);
> >
> > > it fails cause of IllegalAccessError...
> >
> >
> > > Does someone has a clue? (plugin dependencies are correct because
> > > the class is found and it can be instanciated.
> >
> >
> > > Thanks
> >
> > > Martin(Kersten)
> >
> >
>
>
Previous Topic:using jdk1.1.8 -Xbootclasspath
Next Topic:Is there a flow chart diagram plugin available
Goto Forum:
  


Current Time: Fri May 09 23:21:42 EDT 2025

Powered by FUDForum. Page generated in 0.04393 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top