Skip to content

Commit

Permalink
Invalid boolean values now produce a warning. closes #85
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lawrey committed May 16, 2018
1 parent 85f5d5d commit bdf2a53
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/openhft/chronicle/wire/TextWire.java
Original file line number Diff line number Diff line change
Expand Up @@ -3142,7 +3142,8 @@ public boolean bool() {
return true;
if (ObjectUtils.isFalse(sb))
return false;
throw new IORuntimeException("Unable to parse '" + sb + "' as a boolean flag");
Jvm.debug().on(getClass(), "Unable to parse '" + sb + "' as a boolean flag, assuming false");
return false;
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/openhft/chronicle/wire/Wires.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,9 @@ public static <E> E object0(ValueIn in, @Nullable E using, @Nullable Class clazz

case NONE:
@NotNull final Object e = strategy.readUsing(using, in);
return clazz == Base64.class ? (E) e : (E) ObjectUtils.convertTo(clazz, e);
return clazz == Base64.class
? (E) e
: (E) ObjectUtils.convertTo(clazz, e);

default:
throw new AssertionError();
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/net/openhft/chronicle/wire/TextWireTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,37 @@ public void testSimpleBool() {
assertEquals(true, wire.read(() -> "T").bool());
}

@Test
public void testFailingBool() {
@NotNull Wire wire = createWire();

wire.write(() -> "A").text("");
wire.write(() -> "B").text("other");
assertEquals("A: \"\"\n" +
"B: other\n", wire.toString());
@NotNull String expected = "{A=, B=other}";
expectWithSnakeYaml(expected, wire);

assertEquals(false, wire.read(() -> "A").bool());
assertEquals(false, wire.read(() -> "B").bool());
}

@Test
public void testFailingBoolean() {
@NotNull Wire wire = createWire();

wire.write(() -> "A").text("");
wire.write(() -> "B").text("other");
assertEquals("A: \"\"\n" +
"B: other\n", wire.toString());
@NotNull String expected = "{A=, B=other}";
expectWithSnakeYaml(expected, wire);

// TODO fix.
// assertEquals(null, wire.read(() -> "A").object(Boolean.class));
assertEquals(false, wire.read(() -> "B").object(Boolean.class));
}

@Test
public void testLeadingSpace() {
@NotNull Wire wire = createWire();
Expand Down

1 comment on commit bdf2a53

@RobAustin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

Please sign in to comment.