Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Method not accessible
Method not accessible [message #758605] Wed, 23 November 2011 20:37 Go to next message
Jakob Braeuchi is currently offline Jakob BraeuchiFriend
Messages: 69
Registered: July 2009
Location: Switzerland
Member
hi,

i do have a problem with the visibility of inherited methods.

bundle1
- package internal.test is NOT exported. it contains an abstract class with methodA()
- package test is exported, this package contains the concrete class inherited from the class in internal.test. this class has a method methodB()

bundle2 requires bundle1
- i create an instance of the concrete class and call methodA() and methodB()
- methodB() is ok but the compiler complains about methodA() being not accessible.

exporting internal.test is not an option, setting the errors/warnings for forbidden access to warning is also not an option. i could implement methodA() in the concrete class as well but i think this is not the way to go.

things get even worse when i add an interface to the public package and have the abstract class implement this interface. with this scenarion methodA() of the concrete class still produces an error, but when i cast this instance to the interface it works:

        TheClass cls = new TheClass();
        
        // ok
        cls.methodB();
        
        // method not visible because the package internal.test of bundle test.bundle1
        // is not exported
        cls.methodA();

        // ok 
        ((TheInterface)cls).methodA(); 


i have attached a zip with the two bundles to demonstrate this problem.

thanks jakob
  • Attachment: OSGiTest.zip
    (Size: 8.52KB, Downloaded 214 times)
Re: Method not accessible [message #758608 is a reply to message #758605] Wed, 23 November 2011 20:45 Go to previous messageGo to next message
Jakob Braeuchi is currently offline Jakob BraeuchiFriend
Messages: 69
Registered: July 2009
Location: Switzerland
Member
forgot to mention that i can successfully call methodA() and methodB() from a TestCase although the compiler marks an error
Re: Method not accessible [message #759279 is a reply to message #758605] Mon, 28 November 2011 09:04 Go to previous messageGo to next message
Ivan Larionov is currently offline Ivan LarionovFriend
Messages: 37
Registered: July 2009
Member
Hi Jakob,

I cannot provide a solution. I can just suggest a workaround.
You may try to export "internal.test" this way:

Export-Package: internal.test; x-internal:=true,
test

Then, while importing dependencies via Require-Bundle, you will be able
to use that method, though getting a warning in place of its invocation
instead of the error.

I am pretty sure someone can suggest a better way. I am looking forward
to it as well.

Regards,
Ivan

On 23.11.2011 22:37, Jakob Braeuchi wrote:
> hi,
>
> i do have a problem with the visibility of inherited methods.
>
> bundle1
> - package internal.test is NOT exported. it contains an abstract class with methodA()
> - package test is exported, this package contains the concrete class inherited from the class in internal.test. this class has a method methodB()
>
> bundle2 requires bundle1
> - i create an instance of the concrete class and call methodA() and methodB()
> - methodB() is ok but the compiler complains about methodA() being not accessible.
>
> exporting internal.test is not an option, setting the errors/warnings for forbidden access to warning is also not an option. i could implement methodA() in the concrete class as well but i think this is not the way to go.
>
> things get even worse when i add an interface to the public package and have the abstract class implement this interface. with this scenarion methodA() of the concrete class still produces an error, but when i cast this instance to the interface it works:
>
>
> TheClass cls = new TheClass();
>
> // ok
> cls.methodB();
>
> // method not visible because the package internal.test of bundle test.bundle1
> // is not exported
> cls.methodA();
>
> // ok
> ((TheInterface)cls).methodA();
>
>
> i have attached a zip with the two bundles to demonstrate this problem.
>
> thanks jakob
>
Re: Method not accessible [message #760762 is a reply to message #759279] Mon, 05 December 2011 06:45 Go to previous messageGo to next message
Jakob Braeuchi is currently offline Jakob BraeuchiFriend
Messages: 69
Registered: July 2009
Location: Switzerland
Member
hi ivan,

thanks for your hint. as you wrote, i got a warning in my code.
actually i do not like to tweak my manifest or my code to solve
a problem that's probably an eclipse error.

jakob
Re: Method not accessible [message #760766 is a reply to message #760762] Mon, 05 December 2011 08:00 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Could this be a variation of
http://mcaffer.com/2011/01/managing-development-time-dependencies/

Tom

Am 05.12.11 07:45, schrieb Jakob Braeuchi:
> hi ivan,
>
> thanks for your hint. as you wrote, i got a warning in my code.
> actually i do not like to tweak my manifest or my code to solve a
> problem that's probably an eclipse error.
>
> jakob
Re: Method not accessible [message #764462 is a reply to message #760766] Mon, 12 December 2011 08:23 Go to previous messageGo to next message
Jakob Braeuchi is currently offline Jakob BraeuchiFriend
Messages: 69
Registered: July 2009
Location: Switzerland
Member
hi tom,

thanks for the link.
but i dont't think it's the same problem. this guy describes plugin dependencies; but i do have issues with package visibility and PDE's Automated Management of Dependencies is no help.

jakob
Re: Method not accessible [message #765107 is a reply to message #760766] Tue, 13 December 2011 12:37 Go to previous message
Ivan Larionov is currently offline Ivan LarionovFriend
Messages: 37
Registered: July 2009
Member
I am afraid it is not.

On 05.12.2011 10:00, Tom Schindl wrote:
> Could this be a variation of
> http://mcaffer.com/2011/01/managing-development-time-dependencies/
>
> Tom
>
> Am 05.12.11 07:45, schrieb Jakob Braeuchi:
>> hi ivan,
>>
>> thanks for your hint. as you wrote, i got a warning in my code.
>> actually i do not like to tweak my manifest or my code to solve a
>> problem that's probably an eclipse error.
>>
>> jakob
>
Previous Topic:provisioning question
Next Topic:Jetty hosted in Equinox: can Jetty code access Equionox hosted bundles?
Goto Forum:
  


Current Time: Thu Apr 25 11:13:06 GMT 2024

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

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

Back to the top