compiler lint warning from use of aQute.bnd ServiceProvider

217 views
Skip to first unread message

Chris Hegarty

unread,
Sep 16, 2022, 4:37:28 PM9/16/22
to jackson-dev
Hi,

I'm encountering an issue when compiling against the latest Jackson 2.14.0-SNAPSHOT. The issue only arises when lint warnings are enabled - it's quite common to enable some or all lint warnings and also treat warnings as errors (which we do in Elasticsearch).

The issue relates to the use of the `aQute.bnd.annotation.spi.ServiceProvider` annotation in `JsonFactory`. I've included inline a trivial minimal test that demonstrates the issue, along with the warning message.

For now, I'm working around this issue by disabling `classfile` lint warnings, with `-Xlint:-classfile`. [1]

```
$ cat T.java
public class T {
  com.fasterxml.jackson.core.JsonFactory jsonFactory = null;
}

```

```
$ binaries/jdk-17.0.2.jdk/Contents/Home/bin/javac \
  -cp .gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.14.0-SNAPSHOT/3f27917aee3d16732aa59a78ee5104cc7bd24fef/jackson-core-2.14.0-SNAPSHOT.jar \
  -Xlint:all \
  T.java

.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.14.0-SNAPSHOT/3f27917aee3d16732aa59a78ee5104cc7bd24fef/jackson-core-2.14.0-SNAPSHOT.jar(/com/fasterxml/jackson/core/JsonFactory.class): warning: Cannot find annotation method 'value()' in type 'ServiceProvider': class file for aQute.bnd.annotation.spi.ServiceProvider not found
1 warning
```

Thanks,
-Chris.




Tatu Saloranta

unread,
Sep 16, 2022, 5:18:08 PM9/16/22
to jacks...@googlegroups.com
Ok, so this annotation was added for better OSGi support as per:

https://github.com/FasterXML/jackson-core/issues/768

but would not want to add a requirement for non-OSGi users to have a
dependency to OSGi annotations.

Is there some actual problem here, or just general concern it might be
problematic? My understanding of Java annotation
handling is that JVM, JDK and class loaders must assume that
annotation definitions may well not be available in many cases.
And so missing should not be considered an error condition.

-+ Tatu +-

Chris Hegarty

unread,
Sep 19, 2022, 7:32:12 AM9/19/22
to jackson-dev
Hi Tatu,

Thank you for your reply. Comments inline.

On Friday, September 16, 2022 at 10:18:08 PM UTC+1 Tatu Saloranta wrote:
...

Ok, so this annotation was added for better OSGi support as per:

https://github.com/FasterXML/jackson-core/issues/768

but would not want to add a requirement for non-OSGi users to have a
dependency to OSGi annotations.

Ok, that explains why this new lint warning is occurring. 
 
Is there some actual problem here, or just general concern it might be
problematic? My understanding of Java annotation
handling is that JVM, JDK and class loaders must assume that
annotation definitions may well not be available in many cases.
And so missing should not be considered an error condition.

There is no immediate issue - everything operates as expected without the presence of `aQute.bnd.annotation`.

I raised this as a "mild" concern, to ensure that the compile-time (with Xlint:classfiledependency on `aQute.bnd.annotation` was explicitly known (rather than any oversight). It's fine to leave things exactly as they are - folk compiling against Jackson core will just have to disable the `classfile` lint option. (this is most noticeable when compiling with warnings as errors, -Werror)

-Chris.

Reply all
Reply to author
Forward
0 new messages