Skip to content

Commit

Permalink
fix: Build by moving from findbugs to spotbugs and removing Java 7 tests
Browse files Browse the repository at this point in the history
Actually the Travis build on master is broken because of an issue with findbugs 3.
Since findbugs is deprecated, its seems to be better to switch to spotbugs, the successor.
The pom.xml has been updated accordingly and some low hanging fruits have been fixed.

However the test show some concurrency issue, which might be considered to be fixed.

The test for Java 7 has been switched off in Travis as (a) the build is broken (see one of the latest Travis logs) and (b) spotbugs requires Java 8+
  • Loading branch information
rhuss committed Jan 9, 2020
1 parent 96a3533 commit 1650e10
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: java
jdk:
- openjdk7
- openjdk8
- openjdk9
notifications:
Expand Down
24 changes: 16 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,20 @@
</executions>
</plugin>

<!-- run findbugs check -->
<!-- run spotbugs check -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
<executions>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.12.2</version>
<dependencies>
<!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>4.0.0-beta4</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>process-test-classes</phase>
<goals>
Expand All @@ -124,9 +132,9 @@
</executions>
<configuration>
<effort>Max</effort>
<includeTests>true</includeTests>
<threshold>Low</threshold>
<xmlOutput>true</xmlOutput>
<includeTests>false</includeTests>
<relaxed>true</relaxed>
<spotbugsXmlOutput>true</spotbugsXmlOutput>
<failOnError>false</failOnError>
</configuration>
</plugin>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/jnr/unixsocket/UnixDatagramChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ private UnixDatagramChannel() throws IOException {
UnixDatagramChannel(int fd, State initialState, boolean initialBoundState) {
super(fd);
stateLock.writeLock().lock();
state = initialState;
bindHandler = new BindHandler(initialBoundState);
stateLock.writeLock().unlock();
try {
state = initialState;
bindHandler = new BindHandler(initialBoundState);
} finally {
stateLock.writeLock().unlock();
}
}

UnixDatagramChannel(int fd, UnixSocketAddress remote) throws IOException {
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/jnr/unixsocket/UnixSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ public InputStream getInputStream() throws IOException {

@Override
public SocketAddress getLocalSocketAddress() {
UnixSocketAddress address = chan.getLocalSocketAddress();
if (address != null) {
return address;
} else {
return null;
}
return chan.getLocalSocketAddress();
}

@Override
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/jnr/unixsocket/UnixSocketChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static final UnixSocketChannel create() throws IOException {
public static final UnixSocketChannel[] pair() throws IOException {
int[] sockets = { -1, -1 };
Native.socketpair(ProtocolFamily.PF_UNIX, Sock.SOCK_STREAM, 0, sockets);
return new UnixSocketChannel[] {
return new UnixSocketChannel[] {
new UnixSocketChannel(sockets[0], State.CONNECTED, true),
new UnixSocketChannel(sockets[1], State.CONNECTED, true) };
}
Expand All @@ -100,17 +100,20 @@ public static final UnixSocketChannel fromFD(int fd) {
UnixSocketChannel() throws IOException {
this(Native.socket(ProtocolFamily.PF_UNIX, Sock.SOCK_STREAM, 0));
}

UnixSocketChannel(int fd) {
this(fd, State.CONNECTED, false);
}

UnixSocketChannel(int fd, State initialState, boolean initialBoundState) {
super(fd);
stateLock.writeLock().lock();
state = initialState;
bindHandler = new BindHandler(initialBoundState);
stateLock.writeLock().unlock();
try {
state = initialState;
bindHandler = new BindHandler(initialBoundState);
} finally {
stateLock.writeLock().unlock();
}
}

private boolean doConnect(SockAddrUnix remote) throws IOException {
Expand Down Expand Up @@ -146,7 +149,7 @@ public boolean connect(UnixSocketAddress remote) throws IOException {
return true;
}
}

boolean isBound() {
return bindHandler.isBound();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/jnr/unixsocket/example/UnixServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public final boolean rxready() {
ByteBuffer buf = ByteBuffer.allocate(1024);
int n = channel.read(buf);
UnixSocketAddress remote = channel.getRemoteSocketAddress();
System.out.printf("Read in %d bytes from %s\n", n, remote);
System.out.printf("Read in %d bytes from %s%n", n, remote);

if (n > 0) {
buf.flip();
Expand Down

0 comments on commit 1650e10

Please sign in to comment.