Skip to content

Commit 24826e4

Browse files
author
Peter Hill
committed
fixed a number of spotbugs issues
1 parent 2cdbdb5 commit 24826e4

7 files changed

Lines changed: 259 additions & 235 deletions

File tree

src/main/java/net/juniper/netconf/Device.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,7 @@ public boolean isStrictHostKeyChecking() {
12761276
*
12771277
* @return the underlying {@link JSch} SSH client
12781278
*/
1279+
@SuppressWarnings("EI_EXPOSE_REP") // Defensive copy not feasible for JSch
12791280
public JSch getSshClient() {
12801281
// Defensive copy not possible; document that caller must not modify
12811282
return sshClient;
@@ -1385,6 +1386,7 @@ public String getHostKeysFileName() {
13851386
*
13861387
* @return the {@link DocumentBuilder} in use
13871388
*/
1389+
@SuppressWarnings("EI_EXPOSE_REP") // Defensive copy not feasible for DocumentBuilder
13881390
public DocumentBuilder getXmlBuilder() {
13891391
// Defensive copy not possible; document that caller must not modify
13901392
return xmlBuilder;
@@ -1416,6 +1418,7 @@ public String getHelloRpc() {
14161418
*
14171419
* @return active SSH subsystem channel, or {@code null}
14181420
*/
1421+
@SuppressWarnings("EI_EXPOSE_REP") // Defensive copy not feasible for active channel
14191422
public ChannelSubsystem getSshChannel() {
14201423
return sshChannel; // Defensive copy not feasible; caller must not modify
14211424
}
@@ -1426,6 +1429,7 @@ public ChannelSubsystem getSshChannel() {
14261429
*
14271430
* @return SSH session, or {@code null}
14281431
*/
1432+
@SuppressWarnings("EI_EXPOSE_REP") // Defensive copy not feasible for active session
14291433
public Session getSshSession() {
14301434
return sshSession; // Defensive copy not feasible; caller must not modify
14311435
}
@@ -1436,6 +1440,7 @@ public Session getSshSession() {
14361440
*
14371441
* @return active Netconf session, or {@code null}
14381442
*/
1443+
@SuppressWarnings("EI_EXPOSE_REP") // Defensive copy not feasible for active session
14391444
public NetconfSession getNetconfSession() {
14401445
return netconfSession; // Defensive copy not feasible; caller must not modify
14411446
}
@@ -1451,6 +1456,7 @@ public NetconfSession getNetconfSession() {
14511456
* @param sshChannel the SSH channel subsystem (must not be null)
14521457
* @throws NullPointerException if sshChannel is null
14531458
*/
1459+
@SuppressWarnings("EI_EXPOSE_REP2") // Defensive copy not feasible for active channel
14541460
public void setSshChannel(ChannelSubsystem sshChannel) {
14551461
this.sshChannel = (ChannelSubsystem) Objects.requireNonNull(sshChannel);
14561462
}
@@ -1464,6 +1470,7 @@ public void setSshChannel(ChannelSubsystem sshChannel) {
14641470
* @param sshSession the SSH session (must not be null)
14651471
* @throws NullPointerException if sshSession is null
14661472
*/
1473+
@SuppressWarnings("EI_EXPOSE_REP2") // Defensive copy not feasible for active session
14671474
public void setSshSession(Session sshSession) {
14681475
this.sshSession = Objects.requireNonNull(sshSession);
14691476
}
@@ -1477,6 +1484,7 @@ public void setSshSession(Session sshSession) {
14771484
* @param netconfSession the Netconf session (must not be null)
14781485
* @throws NullPointerException if netconfSession is null
14791486
*/
1487+
@SuppressWarnings("EI_EXPOSE_REP2") // Defensive copy not feasible for active session
14801488
public void setNetconfSession(NetconfSession netconfSession) {
14811489
this.netconfSession = Objects.requireNonNull(netconfSession);
14821490
}

src/main/java/net/juniper/netconf/LoadException.java

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,50 @@
33
All Rights Reserved
44
55
Use is subject to license terms.
6-
76
*/
87

98
package net.juniper.netconf;
109

1110
import java.io.IOException;
1211

13-
/**
14-
* Describes exceptions related to load operation
12+
/**
13+
* Exception thrown when a <em>load</em> RPC returns &lt;rpc-error&gt; or otherwise
14+
* fails to complete successfully.
15+
*
16+
* <p>Three convenient constructors are provided so callers can supply:
17+
* <ol>
18+
* <li>a human‑readable message only,</li>
19+
* <li>a message and root cause, or</li>
20+
* <li>just the root cause.</li>
21+
* </ol>
1522
*/
1623
public class LoadException extends IOException {
1724

18-
LoadException(String msg) {
19-
super(msg);
25+
/**
26+
* Creates a {@code LoadException} with the supplied message.
27+
*
28+
* @param message description of the load failure
29+
*/
30+
public LoadException(String message) {
31+
super(message);
32+
}
33+
34+
/**
35+
* Creates a {@code LoadException} with a message and a root cause.
36+
*
37+
* @param message description of the load failure
38+
* @param cause underlying exception that triggered the failure
39+
*/
40+
public LoadException(String message, Throwable cause) {
41+
super(message, cause);
42+
}
43+
44+
/**
45+
* Creates a {@code LoadException} that wraps an underlying cause.
46+
*
47+
* @param cause underlying exception that triggered the failure
48+
*/
49+
public LoadException(Throwable cause) {
50+
super(cause);
2051
}
2152
}

src/main/java/net/juniper/netconf/NetconfSession.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,16 @@ public void loadXMLConfiguration(String configuration, String loadType) throws I
229229
"</edit-config>" +
230230
"</rpc>" +
231231
NetconfConstants.DEVICE_PROMPT;
232-
setLastRpcReply(getRpcReply(rpc));
233-
if (hasError() || !isOK())
232+
try {
233+
setLastRpcReply(getRpcReply(rpc));
234+
} catch (NetconfException e) {
235+
// Propagate as a LoadException so the caller knows this happened
236+
throw new LoadException("Load operation returned error.", e);
237+
}
238+
239+
if (hasError() || !isOK()) {
234240
throw new LoadException("Load operation returned error.");
241+
}
235242
}
236243

237244
private void setHelloReply(final String reply) throws IOException {
@@ -285,9 +292,15 @@ public void loadTextConfiguration(String configuration, String loadType) throws
285292
"</edit-config>" +
286293
"</rpc>" +
287294
NetconfConstants.DEVICE_PROMPT;
288-
setLastRpcReply(getRpcReply(rpc));
289-
if (hasError() || !isOK())
295+
try {
296+
setLastRpcReply(getRpcReply(rpc));
297+
} catch (NetconfException e) {
298+
throw new LoadException("Load operation returned error.", e);
299+
}
300+
301+
if (hasError() || !isOK()) {
290302
throw new LoadException("Load operation returned error");
303+
}
291304
}
292305

293306
private String getConfig(String configTree) throws IOException {
@@ -392,21 +405,7 @@ public Hello getServerHello() {
392405
}
393406

394407
/**
395-
* Send an RPC (as String object) over the default Netconf session and get
396-
* the response as an XML object.
397-
*
398-
* @param rpcContent RPC content to be sent. For example, to send an rpc
399-
* &lt;rpc&gt;&lt;get-chassis-inventory/&gt;&lt;/rpc&gt;, the
400-
* String to be passed can be
401-
* "&lt;get-chassis-inventory/&gt;" OR
402-
* "get-chassis-inventory" OR
403-
* "&lt;rpc&gt;&lt;get-chassis-inventory/&gt;&lt;/rpc&gt;"
404-
* @return RPC reply sent by Netconf server
405-
* @throws org.xml.sax.SAXException If the XML Reply cannot be parsed.
406-
* @throws java.io.IOException If there are issues communicating with the netconf server.
407-
*/
408-
/**
409-
* Sends a raw RPC string, waits for the <rpc-reply>, and converts the
408+
* Sends a raw RPC string, waits for the {@code &lt;rpc-reply&gt;}, and converts the
410409
* response to an {@link XML} object.
411410
* <p>
412411
* If the server includes any {@code &lt;rpc-error&gt;} elements, the call

src/main/java/net/juniper/netconf/element/RpcError.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ public static class Builder {
355355
private String errElement;
356356
private String noOpElement;
357357

358+
/**
359+
* Creates a new builder instance with all fields initialized to null.
360+
*/
361+
public Builder() {
362+
// Default constructor - all fields start as null
363+
}
364+
358365
/**
359366
* Sets the name of the attribute that caused the error.
360367
*

0 commit comments

Comments
 (0)