Fix Klocwork issues (#7)
* Fix issue 6: empty catch block
* Fix issue 6: empty catch block
* Fix issue 7: check data name size to avoid runtime exceptions
* Fix issue 10: Avoid catching nullPointerException
* Bump version
Also fixes a minor checkstyle issue (line too long)
diff --git a/src/main/java/com/intel/jndn/management/Nfdc.java b/src/main/java/com/intel/jndn/management/Nfdc.java
index f8a780d..2be7755 100644
--- a/src/main/java/com/intel/jndn/management/Nfdc.java
+++ b/src/main/java/com/intel/jndn/management/Nfdc.java
@@ -569,12 +569,16 @@
*/
private static ControlResponse sendCommand(final Face face, final Name name) throws IOException, EncodingException,
ManagementException {
+ if (face == null) {
+ throw new IllegalArgumentException("Face parameter is null.");
+ }
+
Interest interest = new Interest(name);
// forwarder must have command signing info set
try {
face.makeCommandInterest(interest);
- } catch (NullPointerException | SecurityException e) {
+ } catch (SecurityException e) {
throw new IllegalArgumentException("Failed to make command interest; ensure command signing info is set on the " +
"face.", e);
}
diff --git a/src/main/java/com/intel/jndn/management/helpers/FetchHelper.java b/src/main/java/com/intel/jndn/management/helpers/FetchHelper.java
index 2b92a54..b22a18a 100644
--- a/src/main/java/com/intel/jndn/management/helpers/FetchHelper.java
+++ b/src/main/java/com/intel/jndn/management/helpers/FetchHelper.java
@@ -28,11 +28,10 @@
import java.util.logging.Logger;
/**
- * Trival NDN client to fetch one or multiple Data packets.
+ * Trivial NDN client to fetch one or multiple data packets.
*/
public final class FetchHelper implements OnData, OnTimeout {
- public static final long DEFAULT_TIMEOUT = 2000;
-
+ private static final long DEFAULT_TIMEOUT = 2000;
private static final Logger LOG = Logger.getLogger(FetchHelper.class.getName());
private static final int SLEEP_TIMEOUT = 20;
private static final int SEGMENT_NAME_COMPONENT_OFFSET = -1;
@@ -44,12 +43,6 @@
/////////////////////////////////////////////////////////////////////////////
/**
- * Prevent creation of FetchHelper instances: use getData or getSegmentedData.
- */
- private FetchHelper() {
- }
-
- /**
* Private constructor: use getData or getSegmentedData.
*/
private FetchHelper(final Face face) {
@@ -119,16 +112,18 @@
Data data = fetcher.getData(interest);
- try {
- data.getName().get(SEGMENT_NAME_COMPONENT_OFFSET).toSegment();
- } catch (ArrayIndexOutOfBoundsException | EncodingException e) {
- throw new IOException("Retrieved data does not have segment number as the last name component", e);
- }
if (data.getName().size() != prefix.size() + 2) {
- throw new IOException("Retrieved data is not part of segmented stream");
+ throw new IOException("Retrieved data is not part of segmented stream; " +
+ "data name must end with .../[version]/[segment]");
}
- long finalBlockId = 0;
+ try {
+ data.getName().get(SEGMENT_NAME_COMPONENT_OFFSET).toSegment();
+ } catch (EncodingException e) {
+ throw new IOException("Retrieved data does not have segment number as the last name component", e);
+ }
+
+ long finalBlockId;
try {
finalBlockId = data.getMetaInfo().getFinalBlockId().toSegment();
} catch (EncodingException e) {
@@ -167,7 +162,7 @@
try {
Thread.sleep(SLEEP_TIMEOUT);
} catch (InterruptedException e) {
- // ok
+ Thread.currentThread().interrupt();
}
}
@@ -189,7 +184,7 @@
state.nRetries--;
if (state.nRetries > 0) {
try {
- face.expressInterest(new Interest(interest).setNonce(null), this, this);
+ face.expressInterest(new Interest(interest), this, this);
} catch (IOException e) {
LOG.log(Level.INFO, "Error while expressing interest: " + e.toString(), e);
}