0

I want to wrap a third party jar. Unfortunately the vendor placed one single class (a.class) with one single method into the default package.

When I try to include the resource using Include-Resource: @lib/acme-8.0.jar, it results in the following error:

The default package '.' is not permitted by the Import-Package syntax.
This can be caused by compile errors in Eclipse because Eclipse creates valid class files regardless of compile errors.
The following package(s) import from the default package [com.acme.util]

bnd print -all acme-8.0.jar gives me the following output (shortened, vendor name replaced with acme)

[API USES]
.                                        []

com.acme.common                            []

com.acme.acmedrt                             [com.acme.acmedrt.types, com.acme.acmedrt.comm.jobtransport, com.acme.acmedrt.workflow.type
s]

com.acme.acmedrt.impl                        [com.acme.acmedrt, com.acme.acmedrt.types, org.apache.commons.logging, com.acme.acmedrt.imp
l.types, com.acme.acmedrt.comm.jobtransport, com.acme.acmedrt.pool, org.apache.commons.pool, com.acme.acmedrt.workflow.types]

com.acme.acmedrt.impl.types                  [com.acme.acmedrt.types, com.acme.acmedrt, com.acme.acmedrt.impl, org.xml.sax]

com.acme.acmedrt.notification                [com.acme.acmedrt]

com.acme.acmedrt.pool                        [com.acme.acmedrt, com.acme.acmedrt.impl.types, com.acme.acmedrt.impl, com.acme.acmedrt.types,
org.apache.commons.pool, com.acme.acmedrt.workflow.types]

com.acme.acmedrt.types                       [com.acme.acmedrt, com.acme.common]

com.acme.acmedrt.util                        []

com.acme.acmedrt.workflow.types              [com.acme.common]

com.acme.tools                             []

com.acme.util                              []

com.acme.util.xml                          []


[LIST]

  a.class
META-INF
  MANIFEST.MF
com
com <no contents>
com/acme
com/acme <no contents>
com/acme/common
  Enum.class
com/acme/acmedrt
[...]

If I understand this output correctly, several packages use the default package. How is that even possible? As far is I know, you can not import classes from the default package.

I already contacted the vendor with the request to move the offending class. Chances are, that he will not follow my suggestion.

Is there a workaround to handle classes in the default package?

tobias_
  • 468
  • 5
  • 21
  • It's true that you can't import the default package in OSGi. But it should be fine to have classes from the default package inside your bundle. – Neil Bartlett Jan 13 '16 at 00:16
  • @NeilBartlett Maybe, but bnd fails to create a bundle from the given jar resulting in the error message above. – tobias_ Jan 13 '16 at 07:52
  • It looks like the class is the default package is referenced in the API of the other packages. Hence the error message. – BJ Hargrave Jan 13 '16 at 08:06
  • @BJHargrave I agree. But as I said, I don't have any control over the third party jar. Is there a way to take care of this error and creating a bundle without changing the given jar? – tobias_ Jan 13 '16 at 08:11
  • If you cannot move the class into a named package, then you cannot make a bundle out of the jar. The unnamed (default) package cannot be exported or imported. – BJ Hargrave Jan 13 '16 at 10:35

1 Answers1

2

You probably can get away with the following option:

 -fixupmessages: "The default package "
tobias_
  • 468
  • 5
  • 21
Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
  • This option supresses the error message and enables me to create a bundle. However, usage of the library leads to an Exception in some cases ("com/acme/util/a.a(I)Ljava/lang/String; @44: if_icmpge .Expected stackmap frame at this location."). I don't know whether this is related to the missing class in the default package or the result of an unsatisfied dependency. – tobias_ Jan 13 '16 at 13:45
  • 2
    Looking at the message this is unlikely but not impossible ... But if you have a crappy library you have crappy problems ... :-( – Peter Kriens Jan 18 '16 at 11:33
  • The vendor uses code obfuscation for parts of their library. The mentioned error seems to occur when obfuscated code is being called. I contacted the vendor to review their product. – tobias_ Feb 11 '16 at 11:16