xbee-java icon indicating copy to clipboard operation
xbee-java copied to clipboard

Issues (with solutions) found when updating a Java project from V1.1.1 to V1.2.0.

Open pabender opened this issue 9 years ago • 0 comments

I am one of the developers for the JMRI project ( https://github.com/JMRI/ ). Last week, we started the process of upgrading our XBee device support from XBeeJavaLibrary 1.1.1 to XBeeJavaLibrary 1.2.0.

We discovered several issues that appeared when testing that we didn't expect based on the description of the changes in the release notes and the JavaDoc.

First, and most importantly, the XBee libraries use SLF4J to log to JUL (java.util.logging) (also called JDK14 because that is when that logging mechanism was introduced); JMRI uses SLF4J to log to Log4J. SLF4J doesn't like this because there are two logging mechanisms defined.

The short term solution to this problem is to excluding the slf4j-jdk14 dependency in our maven configuration.

The real issue here is actually that the XBee library is mis-configured to require that incorporating projects use JUL logging. ( see https://github.com/digidotcom/XBeeJavaLibrary/blob/master/pom.xml#L223 which establishes the dependency on logging via JUL.)

The long term solution to this problem is to either:

  1. remove the dependency on slf4j-jdk14
  2. change the scope of the dependency on slf4j-jdk14 to test
  3. mark the dependency on slf4j-jdk14 as optional

We believe option 3 is preferred unless the XBeeLibrary only needs slf4j-jdk14 for tests (We don't know if its needed for any example code to function). (see http://maven.apache.org/pom.html#Dependencies for more on this)

Second, There were several findbugs errors in our code that were not present before the version 1.2.0 library was added to the project. We narrowed the issue down to the inclusion of android support by the Digi library.

We were able to eliminate these findbugs warnings by excluding the android-sdk and android-sdk-addon dependencies in our maven configuration.

Finally, When we implemented support for version 1.1.1, we mocked the XBeeDevice object in some of our tests using powermockito. Powermockito had issues with the version 1.2.0 library finding android.content.Context due to the new constructors in the XBeeDevice class that expect android.content.Context objects. In order to work around this, we are now mocking our class that implements IConnectionInterface and then calling the XBeeDevice constructor that expects an IConnectionInterface object.

The relevant portion of our maven pom.xml file (addressing the first two issues above) is copied below

     <dependency>
        <groupId>com.digi.xbee</groupId>
        <artifactId>xbee-java-library</artifactId>
        <version>1.2.0</version>
        <exclusions>
           <exclusion> 
              <groupId>org.slf4j</groupId>
              <artifactId>slf4j-jdk14</artifactId>
           </exclusion>
           <exclusion>
              <groupId>com.digi</groupId>
              <artifactId>android-sdk</artifactId>
           </exclusion>
           <exclusion>
              <groupId>com.digi</groupId>
              <artifactId>android-sdk-addon</artifactId>
           </exclusion>
        </exclusions>
     </dependency>

pabender avatar Mar 27 '17 01:03 pabender