[Demonstration 1]

[Buggy Method]
@Override
public String getAddress() {
    // TODO Get full address of the spoke providers (scheme, url, port, path)
    return "coap:/" + this.getEndpoints().get(0).getAddress().toString();
}

[Buggy Hunk]
return "coap:/" + this.getEndpoints().get(0).getAddress().toString();

[Patch]
return "coap://" + this.interfaceAddress + ":" + Integer.toString(this.getEndpoints().get(0).getAddress().getPort()) + "/";

[Demonstration 2]

[Buggy Method]
@Override
protected void onPostExecute(Address address) {
    super.onPostExecute(address);
    updateCard(address);
}

[Buggy Hunk]
updateCard(address);

[Patch]
if(address != null) updateCard(address);

[Demonstration 3]

[Buggy Method]
@Override
public void run() {
    final Map<Integer, Pair<Address, CloseableByteBufferHandler>> establishedConnections = new HashMap<>();
    final boolean[] closed = new boolean[] { false };
    try {
        OutputStream sout;
        InputStream sin;
        try {
            sout = new GZIPOutputStream(socket.getOutputStream(), true);
            sin = new GZIPInputStream(socket.getInputStream());
        } catch (IOException ee) {
            try {
                socket.close();
            } catch (IOException se) {
            }
            throw ee;
        }
        final DataOutputStream out = new DataOutputStream(sout);
        DataInputStream in = new DataInputStream(sin);
        LOGGER.debug("Accepted connection from: {}", socket.getInetAddress());
        while (true) {
            LOGGER.trace("Server waiting for connection ID");
            final int connectionId = in.readInt();
            LOGGER.trace("Server received connection ID: {}", connectionId);
            int len = in.readInt();
            if (len < 0) {
                int command = -len;
                if (command == ProxyCommons.Commands.ESTABLISH_CONNECTION) {
                    final Address address = in.readBoolean() ? new Address(in.readUTF(), in.readInt()) : null;
                    ReadyFactory factory = proxyServerSide.read(in);
                    //%% Ready r = new QueueReady(queue, factory.create());
                    Ready r = factory.create();
                    r.connect(address, new ReadyConnection() {

                        @Override
                        public void failed(IOException e) {
                            LOGGER.warn("Could not connect to {}", address, e);
                            synchronized (out) {
                                try {
                                    out.writeInt(connectionId);
                                    out.writeInt(-ProxyCommons.Commands.FAIL_CONNECTION);
                                    out.flush();
                                } catch (IOException ioe) {
                                    try {
                                        out.close();
                                    } catch (IOException se) {
                                    }
                                }
                            }
                        }

                        @Override
                        public void connected(FailableCloseableByteBufferHandler write) {
                            synchronized (establishedConnections) {
                                if (closed[0]) {
                                    write.close();
                                    return;
                                }
                                establishedConnections.put(connectionId, new Pair<Address, CloseableByteBufferHandler>(address, write));
                            }
                            synchronized (out) {
                                try {
                                    out.writeInt(connectionId);
                                    out.writeInt(-ProxyCommons.Commands.ESTABLISH_CONNECTION);
                                    out.flush();
                                } catch (IOException ioe) {
                                    try {
                                        out.close();
                                    } catch (IOException se) {
                                    }
                                }
                            }
                        }

                        @Override
                        public void close() {
                            synchronized (out) {
                                try {
                                    out.writeInt(connectionId);
                                    out.writeInt(0);
                                    out.flush();
                                } catch (IOException ioe) {
                                    try {
                                        out.close();
                                    } catch (IOException se) {
                                    }
                                }
                            }
                        }

                        @Override
                        public void handle(Address address, ByteBuffer buffer) {
                            if (!buffer.hasRemaining()) {
                                return;
                            }
                            synchronized (out) {
                                try {
                                    out.writeInt(connectionId);
                                    out.writeInt(buffer.remaining());
                                    if (address == null) {
                                        out.writeBoolean(false);
                                    } else {
                                        out.writeBoolean(true);
                                        out.writeUTF(address.getHost());
                                        out.writeInt(address.getPort());
                                    }
                                    out.write(buffer.array(), buffer.arrayOffset(), buffer.remaining());
                                    out.flush();
                                } catch (IOException ioe) {
                                    try {
                                        out.close();
                                    } catch (IOException se) {
                                    }
                                }
                            }
                            buffer.position(buffer.position() + buffer.remaining());
                        }
                    });
                }
            } else if (len == 0) {
                Pair<Address, CloseableByteBufferHandler> connection;
                synchronized (establishedConnections) {
                    connection = establishedConnections.remove(connectionId);
                }
                if (connection != null) {
                    if (connection.second != null) {
                        connection.second.close();
                    }
                }
            } else {
                Pair<Address, CloseableByteBufferHandler> connection;
                synchronized (establishedConnections) {
                    connection = establishedConnections.get(connectionId);
                }
                Address a;
                if (in.readBoolean()) {
                    a = new Address(in.readUTF(), in.readInt());
                } else {
                    a = (connection == null) ? null : connection.first;
                }
                byte[] b = new byte[len];
                in.readFully(b);
                if (connection != null) {
                    if (!addressesToFilter.contains(a)) {
                        if (connection.second != null) {
                            connection.second.handle(a, ByteBuffer.wrap(b));
                        }
                    }
                } else {
                    LOGGER.debug("Invalid connection ID: {}", connectionId);
                }
            }
        }
    } catch (IOException e) {
        LOGGER.info("Socket closed by peer: {}", e.getMessage());
        try {
            socket.close();
        } catch (IOException ioe) {
        }
        List<CloseableByteBufferHandler> toClose = new LinkedList<>();
        synchronized (establishedConnections) {
            closed[0] = true;
            for (Pair<Address, CloseableByteBufferHandler> connection : establishedConnections.values()) {
                if (connection.second != null) {
                    toClose.add(connection.second);
                }
            }
        }
        for (CloseableByteBufferHandler c : toClose) {
            c.close();
        }
    }
}

[Buggy Hunk]
out.write(buffer.array(), buffer.arrayOffset(), buffer.remaining());

[Patch]
out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());