Skip to content

Commit 8453201

Browse files
committed
JAVA-757: Reverting behavioral change to CommandResult.getException. It now returns null, as before, if there is no exception, instead of throwing IllegalStateException.
1 parent 254eb70 commit 8453201

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/com/mongodb/CommandResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public MongoException getException() {
7878
}
7979
}
8080

81-
throw new IllegalStateException("This method should not be called if there is no exception");
81+
return null;
8282
}
8383

8484
/**

src/test/com/mongodb/CommandResultTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@
2222
import java.net.UnknownHostException;
2323

2424
public class CommandResultTest extends TestCase {
25+
@Test
26+
public void testOkCommandResult() throws UnknownHostException {
27+
CommandResult commandResult = new CommandResult(new ServerAddress("localhost"));
28+
commandResult.put("ok", 1);
29+
assertNull(commandResult.getException());
30+
}
31+
2532
@Test
2633
public void testNullErrorCode() throws UnknownHostException {
2734
CommandResult commandResult = new CommandResult(new ServerAddress("localhost"));
2835
commandResult.put("ok", 0);
36+
assertEquals(CommandFailureException.class, commandResult.getException().getClass());
2937
try {
3038
commandResult.throwOnError();
3139
fail("Should throw");
@@ -40,6 +48,7 @@ public void testCommandFailure() throws UnknownHostException {
4048
CommandResult commandResult = new CommandResult(new ServerAddress("localhost"));
4149
final DBObject result = new BasicDBObject("ok", 0.0).append("errmsg", "no not found").append("code", 5000);
4250
commandResult.putAll(result);
51+
assertEquals(CommandFailureException.class, commandResult.getException().getClass());
4352
try {
4453
commandResult.throwOnError();
4554
fail("Should throw");

0 commit comments

Comments
 (0)