Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tellstick] Fixes a NoClassDefFoundError that caused the Tellstick addon to not work properly #9634

Conversation

kalleboll
Copy link
Contributor

Fixes #7024
The problem was caused by the asynchttpclient dependency that seemed to require another version of the Netty dependency than what is added by the openhab.tp-netty feature.
This caused some of the classes in the ssl package to not be found during initialization.
I fixed it by upgrading the asynchttpclient dependency to a version that use the same version of Netty that is bundled(4.1.42.Final).

Signed-off-by: Jörgen Nilsson mail.jnilsson@gmail.com

…ork properly

Fixes openhab#7024
The problem was caused by the asynchttpclient dependency that seemed to require another version of the Netty dependency than what is added by the openhab.tp-netty feature.
This caused some of the classes in the ssl package to not be found during initialization.
I fixed it by upgrading the asynchttpclient dependency to a version that use the same version of Netty that is bundled(4.1.42.Final).

Signed-off-by: Jörgen Nilsson <mail.jnilsson@gmail.com>
@kalleboll kalleboll force-pushed the 7024-Tellstick-addon-not-working-with-the-latest-builds branch from 9571fed to 0a6a869 Compare January 1, 2021 22:14
@kalleboll
Copy link
Contributor Author

kalleboll commented Jan 2, 2021

A test build of the addon that includes the fix can be found here:
https://github.com/kalleboll/beta-test-binaries/raw/main/org.openhab.binding.tellstick-3.1.0-SNAPSHOT.jar

@Hilbrand Hilbrand added the bug An unexpected problem or unintended behavior of an add-on label Jan 2, 2021
Comment on lines +108 to +125
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
<version>4.1.42.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler-proxy</artifactId>
<version>4.1.42.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-socks</artifactId>
<version>4.1.42.Final</version>
<scope>compile</scope>
</dependency>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you including these dependencies in the binding jar if they are already included in the runtime environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are new dependencies required by the new version of async-http-client.
As far I can tell these are not already included by the openhab.tp-netty feature so I had to add them here specifically.
Not all Netty dependencies are included in that feature and my guess is that only the most used once have been added there so far.
My understanding of the build system is very limited so far by I think I found the openhab.tp-netty definition in this file openhab-core\features\karaf\openhab-tp\src\main\feature\feature.xml. Currently on line 120.
There the included Netty dependencies can be found and they are; netty-buffer, netty-common, netty-codec, netty-codec-http, netty-codec-mqtt, netty-handler, netty-resolver, netty-transport, netty-transport-native-epoll and netty-transport-native-unix-common.

I am quite sure that it will work as well if we add these three dependencies, that I need, to the openhab.tp-netty feature instead but I guess that that will impact all other addons that rely on that feature and it would require a change in the openhab-core. That works for me but as I am unsure of the impact of such a change I think someone with a better knowledge of the build/feature/dependency setup should make that call.

@jannegpriv
Copy link
Contributor

To my knowledge @jarlebh is no longer active in the openHAB community.
Code owner should be changed on this binding.

@kalleboll
Copy link
Contributor Author

To my knowledge @jarlebh is no longer active in the openHAB community.
Code owner should be changed on this binding.

Ok.
Do you know how to initiate that?
Who should I talk to about it (If I should)?

@fwolter
Copy link
Member

fwolter commented Jan 13, 2021

If @jarlebh isn't active anymore and you want to take over, you can simply change it in the CODEOWNERS file at the root of this repo.

@J-N-K
Copy link
Member

J-N-K commented Jan 16, 2021

I would prefer not to use <scope>compile</scope> here but <scope>provided</scope> and add the bundles to the feature.xml. The will be available at runtime then but could be shared with othe bindings requiring them. compile should be used for bundles that are unlikely to be shared by others or require a version that is incompatible with the one provided by the framework. This is not the case here. These are aditional bundles.

@kalleboll
Copy link
Contributor Author

I would prefer not to use <scope>compile</scope> here but <scope>provided</scope> and add the bundles to the feature.xml. The will be available at runtime then but could be shared with othe bindings requiring them. compile should be used for bundles that are unlikely to be shared by others or require a version that is incompatible with the one provided by the framework. This is not the case here. These are aditional bundles.

I am not sure if I misunderstood you maybe, but are you sure? Because I couldn't find a single addon that has a dependency set to provided except for org.openhab.addons.bundles.. dependencies. I guess that is used for addons that depend on other addons.
Anyway I tried to change the dependencies I added to provided and add them as bundles to the feature file instead but then my addon does not load and I get errors like this:
`2021-01-17 03:01:29.695 [WARN ] [org.apache.felix.fileinstall ] - Error while starting bundle: file:/openhab/addons/org.openhab.binding.tellstick-3.1.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.tellstick [208]
Unresolved requirement: Import-Package: io.netty.channel.kqueue; version="[4.1.0,5.0.0)"

    at org.eclipse.osgi.container.Module.start(Module.java:444) ~[org.eclipse.osgi-3.12.100.jar:?]
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) ~[org.eclipse.osgi-3.12.100.jar:?]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [bundleFile:3.6.4]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [bundleFile:3.6.4]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221) [bundleFile:3.6.4]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515) [bundleFile:3.6.4]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [bundleFile:3.6.4]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [bundleFile:3.6.4]

`

@kalleboll kalleboll requested a review from a team as a code owner January 17, 2021 02:33
…ive anymore.

Signed-off-by: Jörgen Nilsson <mail.jnilsson@gmail.com>
@kalleboll kalleboll force-pushed the 7024-Tellstick-addon-not-working-with-the-latest-builds branch from 1b7263b to adb08c2 Compare January 17, 2021 02:56
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<feature name="openhab-binding-tellstick" description="Tellstick Binding" version="${project.version}">
		<feature>openhab-runtime-base</feature>
		<feature>openhab-transport-serial</feature>
		<feature dependency="true">openhab.tp-netty</feature>
		<feature dependency="true">openhab.tp-jaxb</feature>
		<bundle dependency="true">mvn:net.java.dev.jna/jna/4.5.2</bundle>
		<bundle dependency="true">mvn:net.java.dev.jna/jna-platform/4.5.2</bundle>
		<bundle dependency="true">mvn:io.netty/netty-transport-native-kqueue/4.1.42.Final</bundle>
		<bundle dependency="true">mvn:io.netty/netty-handler-proxy/4.1.42.Final</bundle>
		<bundle dependency="true">mvn:io.netty/netty-codec-socks/4.1.42.Final</bundle>
		<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.tellstick/${project.version}</bundle>
	</feature>

@@ -15,7 +15,7 @@
<name>openHAB Add-ons :: Bundles :: Tellstick Binding</name>

<properties>
<bnd.importpackage>!com.luckycatlabs.*,!com.jcraft.jzlib.*,!org.apache.commons.cli.*,!org.eclipse.swt.*</bnd.importpackage>
<bnd.importpackage>!com.luckycatlabs.*,!com.jcraft.jzlib.*,!org.apache.commons.cli.*,!org.eclipse.swt.*,!javax.activation</bnd.importpackage>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed if I compile locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not needed when compiling but during runtime.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's needed during runtime you must not exclude it. Instead you need to add the required dependency. But I believe that is already present in the target platform anyway, otherwise the karaf plugin should fail to resolve the feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I meant that the change is not needed to be able to compile but it is there to sort out a runtime issue. So in fact it is the opposite, the new version of async-http-client has javax.activation as a transitive dependency but this addon does not seem to use those parts of the async-http-client library so that is why I excluded javax.activation rather than adding the dependency for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. Fine if it works. The other option would be to add

mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.activation-api-1.2.1/1.2.1_2

to the feature. That is activation API we use in other bundles. But fine with me if it works with the exclusion. Up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea maybe that is a nicer solution even though it is not used.
I added that bundle as well and removed the exclude.

@@ -15,7 +15,7 @@
<name>openHAB Add-ons :: Bundles :: Tellstick Binding</name>

<properties>
<bnd.importpackage>!com.luckycatlabs.*,!com.jcraft.jzlib.*,!org.apache.commons.cli.*,!org.eclipse.swt.*</bnd.importpackage>
<bnd.importpackage>!com.luckycatlabs.*,!com.jcraft.jzlib.*,!org.apache.commons.cli.*,!org.eclipse.swt.*,!javax.activation</bnd.importpackage>
<dep.noembedding>netty-transport-native-unix-common,netty-common,netty-transport,netty-transport-native-epoll,netty-buffer,netty-resolver,netty-codec,netty-codec-http,netty-handler</dep.noembedding>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<dep.noembedding>netty-transport-native-unix-common,netty-common,netty-transport,netty-transport-native-epoll,netty-buffer,netty-resolver,netty-codec,netty-codec-http,netty-handler</dep.noembedding>
<dep.noembedding>netty-codec-socks,netty-handler-proxy,netty-transport-native-kqueue,netty-transport-native-unix-common,netty-common,netty-transport,netty-transport-native-epoll,netty-buffer,netty-resolver,netty-codec,netty-codec-http,netty-handler</dep.noembedding>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea sure I can add the dependencies as bundles to the feature file like you wrote above. In fact I had it like that first but I removed it again because I did not see a need for it. Anyway, I have added them back now.
But why would I want to add them to the dep.noembedding as well?
Then what is the point of adding them as a bundle in the first place?
Remember that these are not dependencies that are bundled with the openhab.tp-netty feature so they will not be added that way, like I have commented on an earlier review comment.
Just for the sake of it I tried to add them to the dep.noembedding like you suggested but then I get this error:
2021-01-18 16:54:38.990 [WARN ] [org.apache.felix.fileinstall ] - Error while starting bundle: file:/openhab/addons/org.openhab.binding.tellstick-3.1.0-SNAPSHOT.jar org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.tellstick [208] Unresolved requirement: Import-Package: io.netty.channel.kqueue; version="[4.1.0,5.0.0)"

I took the opportunity to change all the line endings in this and another xml file as it was causing some weird spotless errors for me and I noticed that no other addon had line endings like these files had.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only add the tellstick bundle, it'll not work (the feature is not part of the tellstick bundle but compiled to a feature.xml with all the other bindings. If you decide to install a binding (via addons.cfg or UI) you are not installing the binding-bundle but the binding feature. This contains the bundle and (like in this case) also other bundles or other features).

If you didn't manually install the additonal bundles, the tellstick bundle can't be resolved. That it why it needs to be added to the feature so karaf knows during installation of the tellstick binding it also needs to install the other bundles.

Regarding you other questions: embedding is not the preferred way in an OSGi environment. At best we would have only proper OSGi bundles and don't need to embed bundles at all but add all bundles to the feature. Unfortunately we don't live in such a world. We have some bundles that are not OSGi bundles at all (e.g. javatellstick) or use improper versioning (e.g. incompatible API even if the minor version did not change). Therefore we decided to use embedding for bundles that are either not compatible, very unlikely will be used by other bindings or use different versions than other bindings. To automate that, we embed all bundles with the scope "compile". This scope is also needed for bnd to resolve the bundle in the IDE. That's why we add e.g. netty with scope "compile" to the pom and exclude it from embedding. Netty is used by different bindings (that's why we have the tp.netty feature to keep the used version inline for all binings).

Hope that makes it more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think that makes it a bit clearer.
But I guess it would still technically have worked the way I had it first, even when installing via the UI, as those dependencies was bundled together in the jar file, since the compile scope is used. I mean then it must be on the classpath. But yea I understand if we want to handle "common" dependencies in a special way.

So ok I have now added the three bundles to the dep.noembedding as well.
But after those changes I could not get the binding to work by just dropping it in the addon directory like before.
I read up about Karaf and the OpenHAB console and I managed to get the binding to work by installing the new bundles the binding requires via the console like this:
bundle:install mvn:io.netty/netty-transport-native-kqueue/4.1.42.Final
bundle:install mvn:io.netty/netty-handler-proxy/4.1.42.Final
bundle:install mvn:io.netty/netty-codec-socks/4.1.42.Final

Is this the preferred way to do it? For example if I want someone else to try out an addon before it is released they have to install the required bundles manually first like this?
I searched for some info regarding this but most posts I could find just said to drop the jar in the addon directory but maybe that was for bindings that did not have these kinds of dependencies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to do it that way. But: if it's an update to an existing binding, the preferred way would be to use the bundle-update command (e.g. for tellstick):

update org.openhab.binding.tellstick file:///home/myuser/org.openhab.binding.tellstick-3.1.0-SNAPSHOT.jar

If the bundle is available for download, you can also use

update org.openhab.binding.tellstick https://myserver.mydomain/path/to/file/org.openhab.binding.tellstick-3.1.0-SNAPSHOT.jar

That way only the bundle itself is updated and all dependency stay installed (unlike in case of deinstalling the binding, then the whole feature, so the bundle and it's dependencies if not needed by other bundles, are uninstalled).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that is a good to know.
Thanks for the tip.

@J-N-K
Copy link
Member

J-N-K commented Jan 17, 2021

The provided thing is not working out as expected. I check that this does resolve the feature. Can you check and adapt? I'll fix the missing pom for the tellstick library in the repo.

Added some dependencies as feature bundles as well.

Signed-off-by: Jörgen Nilsson <mail.jnilsson@gmail.com>
@kalleboll
Copy link
Contributor Author

<feature name="openhab-binding-tellstick" description="Tellstick Binding" version="${project.version}">
		<feature>openhab-runtime-base</feature>
		<feature>openhab-transport-serial</feature>
		<feature dependency="true">openhab.tp-netty</feature>
		<feature dependency="true">openhab.tp-jaxb</feature>
		<bundle dependency="true">mvn:net.java.dev.jna/jna/4.5.2</bundle>
		<bundle dependency="true">mvn:net.java.dev.jna/jna-platform/4.5.2</bundle>
		<bundle dependency="true">mvn:io.netty/netty-transport-native-kqueue/4.1.42.Final</bundle>
		<bundle dependency="true">mvn:io.netty/netty-handler-proxy/4.1.42.Final</bundle>
		<bundle dependency="true">mvn:io.netty/netty-codec-socks/4.1.42.Final</bundle>
		<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.tellstick/${project.version}</bundle>
	</feature>

@kalleboll kalleboll closed this Jan 18, 2021
@kalleboll kalleboll reopened this Jan 18, 2021
@kalleboll
Copy link
Contributor Author

The provided thing is not working out as expected. I check that this does resolve the feature. Can you check and adapt? I'll fix the missing pom for the tellstick library in the repo.

I accidently closed this PR but it is opened again now.
What 'thing' it not working? If you mean that the Jenkins build failed, then yea I noticed that. It seems to have failed due to some unrelated tests that does no seem to work. I have merged the latest from main so hopefully it will build successfully this time.
I have made some small changes according to the comments above.

@J-N-K
Copy link
Member

J-N-K commented Jan 18, 2021

I meant the provided scope I suggested earlier.

…it was before as Jenkins complained about it.

Added the tree new bundles to the dep.noembedding as well.

Signed-off-by: Jörgen Nilsson <mail.jnilsson@gmail.com>
Added the javax.activation bundle as well.

Signed-off-by: Jörgen Nilsson <mail.jnilsson@gmail.com>
@J-N-K J-N-K added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Jan 20, 2021
@J-N-K
Copy link
Member

J-N-K commented Jan 20, 2021

Did you check it works? If so, I‘ll merge tomorrow.

@kalleboll
Copy link
Contributor Author

Did you check it works? If so, I‘ll merge tomorrow.

Yes I tested it after the last change as well and it seems to be working.

@J-N-K J-N-K merged commit c0dd8be into openhab:main Jan 20, 2021
@J-N-K J-N-K added this to the 3.1 milestone Jan 20, 2021
themillhousegroup pushed a commit to themillhousegroup/openhab2-addons that referenced this pull request May 10, 2021
Fixes openhab#7024

The problem was caused by the asynchttpclient dependency that seemed to require another version of the Netty dependency than what is added by the openhab.tp-netty feature.
This caused some of the classes in the ssl package to not be found during initialization.
I fixed it by upgrading the asynchttpclient dependency to a version that use the same version of Netty that is bundled(4.1.42.Final).

Signed-off-by: Jörgen Nilsson <mail.jnilsson@gmail.com>
Signed-off-by: John Marshall <john.marshall.au@gmail.com>
thinkingstone pushed a commit to thinkingstone/openhab-addons that referenced this pull request Nov 7, 2021
Fixes openhab#7024

The problem was caused by the asynchttpclient dependency that seemed to require another version of the Netty dependency than what is added by the openhab.tp-netty feature.
This caused some of the classes in the ssl package to not be found during initialization.
I fixed it by upgrading the asynchttpclient dependency to a version that use the same version of Netty that is bundled(4.1.42.Final).

Signed-off-by: Jörgen Nilsson <mail.jnilsson@gmail.com>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
Fixes openhab#7024

The problem was caused by the asynchttpclient dependency that seemed to require another version of the Netty dependency than what is added by the openhab.tp-netty feature.
This caused some of the classes in the ssl package to not be found during initialization.
I fixed it by upgrading the asynchttpclient dependency to a version that use the same version of Netty that is bundled(4.1.42.Final).

Signed-off-by: Jörgen Nilsson <mail.jnilsson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tellstick] Addon not working with the latest builds
6 participants