Skip to content

Commit

Permalink
Introduce friendlier NumberFormatException messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Oct 21, 2020
1 parent e0b9093 commit 6d64c6f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
3 changes: 3 additions & 0 deletions api/.cache/formatter-maven-cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Wed Oct 21 17:43:26 BRT 2020
/src/main/java/io/smallrye/converters/api/Converters.java=b06664b19f95e0b81a3569936b1ba2e8dbbc7a18ebcb6d8d3508f8af37705b8d07cd0cf343acc6bdbf5ca0beef5b57755b32db23c7521c42f15f66821e1c6c93
/src/main/java/io/smallrye/converters/api/Converter.java=9662401ce4e32250083932b0b680d65f2d7d5d602ef223ed54f1b62f1a5565012c19754337764582d77a9890a09efc6582ca7bf975438c95e3bf64c7c53da0f6
18 changes: 18 additions & 0 deletions implementation/.cache/formatter-maven-cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Wed Oct 21 17:44:11 BRT 2020
/src/main/java/io/smallrye/converters/SmallRyeConvertersBuilder.java=250bcb6c000e87dee245f9f91ecf48a7956abfdcce8e71a725133a151e680191466e3cc7db93be10b08da52947b6ad20f52b6a17756dfc615a8262218c3ebf47
/src/main/java/io/smallrye/converters/Converters.java=7d1948dd474ffc047eaff31e0d0ae1e04bd447de6fcc0042dd93ee387c57e017cbb10f4d5f143a642b40304fa8deefbdb47919868137680f7e412eaff90eaf11
/src/main/java/io/smallrye/converters/ImplicitConverters.java=ab9bd3aad3b6ec48a136ad83caf1be386c5ef88067341490a8d4ff8a46e9b42f9b3b42f58a5bb00676e6270f7f426bf70c9a92866d33976cc6c7bb6ce1e122ee
/src/test/java/io/smallrye/converters/ConvertersTestCase.java=daca976df4a37e20a08039a8cb6d5db6c6f23ee9d9d5e9f856a3625719d2c66074ed4ef3b567ad024e11a04268ad440c666eb0440bf8274af51b75a00868bcbc
/src/test/java/io/smallrye/converters/ConvertersStringCleanupTestCase.java=cccf22ccc9f800bce3fee41f5b19c7cf76e18d604c3c6e5684877eb5325ded1a4004f86b1200960f0f4bf369e0bd263a9c3b1fadd54442839ac1bf8c4c915c05
/src/main/java/io/smallrye/converters/AbstractSimpleDelegatingConverter.java=a73455ed4bbfe9c4169df7f15edc32cdae595b9a92ee69df817fd6ce02d13e394b7f66b168d55d40511e09a1384d7e438eaec632f9d48faf58e580bff56dd8c2
/src/main/java/io/smallrye/converters/ConverterMessages.java=48b66e5c23b0e1085bed7b44de16a67b1b2df7c17869f7d6b23e010f605741370249f9d73248c4a3ffe496e05528bc267be6f1de2c91715c324298060e3f2339
/src/test/java/io/smallrye/converters/ImplicitConverterTestCase.java=364d6c62253ca577ca0f1f2457dd79571e3c8b30a10b90d4d976081181471d0c85b2f05225154d654ab835e020f18b67d0ca659060d6d11a43d5f271f23d4394
/src/test/java/io/smallrye/converters/SmallRyeConvertersBuilderTest.java=3ceb2d2dd1b5d246bbbd3f66cbc03e909ac907a8e9dc9c63b44065416d672feb669e16c04052c1bf14a170d9840bc85ba9ef76baf44ae5a4fd771dd27855b2e6
/src/main/java/io/smallrye/converters/AbstractConverter.java=cc0b094fbee561598f7063727129f5f51eb1ef673e774a7db5ab7d5c7f1ab5ea89f69785dc930e59f6911627159d3c84d67d3ad92c7706aa85c92f2519191573
/src/main/java/io/smallrye/converters/ConverterLogging.java=e3904537515e907a45ec1c399f454a78da65d3fbe69d8f80fafc6712a81b784ea597a6cdf0707b9473286ae38b0d9cf9c066b8825efdca942c0256632bdd0c4e
/src/test/java/io/smallrye/converters/SmallRyeConvertersTest.java=1e2fb2822440c6640e68f7bd1874022d3fe438aab8239bcfe7bc5d7f1cecad6cd1115d159f1d24095b36c2d0187c45181118de30ae8a04d2719766eaf428bd60
/src/main/java/io/smallrye/converters/StringUtil.java=9b97a9957766f9d329fc5a19145978c1c5b76b5a769cc03f4c25173174dd69687447ab36b7f21ad1259adc32364716c0ea03739363d698fe8a52a178b327c131
/src/main/java/io/smallrye/converters/SmallRyeConverters.java=583f888b4a3f65aeee830273bc55053bdb370c1bb13ab8bcaefad88a9059cfcd6b5cdecb81cab28a75f6bdec90eb70da4377045c9b0176980ff562c27ba95498
/src/main/java/io/smallrye/converters/AbstractDelegatingConverter.java=94b9d8b528c8ded52d1b2d643788dc4d24d1611317ebf17e2710d6f1629621feec3d9a01770583e5149794a318e5a8083a50118aff085784d7adad77af4120a8
/src/main/java/io/smallrye/converters/SecuritySupport.java=e3a36602d0f69cde3feb1b78268326371ea56d3703180402cf40c5474cf470efa9cec0b83f720d3684cac9e5ea16e8c118107ad80fbfd69013e83b7ccedbea13
/src/test/java/io/smallrye/converters/CustomConverterTestCase.java=208b11777151df76f468e530076206d8b68cb305461a20fcab4d3ca6b14bc72698511e12275c293ac27e9acfd09edb4c0b45194df5cba91ab613ab02e52ce859
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ interface ConverterMessages {

@Message(id = 16, value = "Can not add converter %s that is not parameterized with a type")
IllegalStateException unableToAddConverter(Converter<?> converter);
}

@Message(id = 17, value = "Expected an integer value, got \"%s\"")
NumberFormatException integerExpected(String value);

@Message(id = 18, value = "Expected a long value, got \"%s\"")
NumberFormatException longExpected(String value);

@Message(id = 19, value = "Expected a double value, got \"%s\"")
NumberFormatException doubleExpected(String value);

@Message(id = 20, value = "Expected a float value, got \"%s\"")
NumberFormatException floatExpected(String value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,40 @@ private Converters() {
|| "OUI".equalsIgnoreCase(value)))));

static final Converter<Double> DOUBLE_CONVERTER = BuiltInConverter.of(2,
newTrimmingConverter(newEmptyValueConverter(Double::valueOf)));
newTrimmingConverter(newEmptyValueConverter(value -> {
try {
return Double.valueOf(value);
} catch (NumberFormatException nfe) {
throw ConverterMessages.msg.doubleExpected(value);
}
})));

static final Converter<Float> FLOAT_CONVERTER = BuiltInConverter.of(3,
newTrimmingConverter(newEmptyValueConverter(Float::valueOf)));
newTrimmingConverter(newEmptyValueConverter(value -> {
try {
return Float.valueOf(value);
} catch (NumberFormatException nfe) {
throw ConverterMessages.msg.floatExpected(value);
}
})));

static final Converter<Long> LONG_CONVERTER = BuiltInConverter.of(4,
newTrimmingConverter(newEmptyValueConverter(Long::valueOf)));
newTrimmingConverter(newEmptyValueConverter(value -> {
try {
return Long.valueOf(value);
} catch (NumberFormatException nfe) {
throw ConverterMessages.msg.longExpected(value);
}
})));

static final Converter<Integer> INTEGER_CONVERTER = BuiltInConverter.of(5,
newTrimmingConverter(newEmptyValueConverter(Integer::valueOf)));
newTrimmingConverter(newEmptyValueConverter(value -> {
try {
return Integer.valueOf(value);
} catch (NumberFormatException nfe) {
throw ConverterMessages.msg.integerExpected(value);
}
})));

static final Converter<Class<?>> CLASS_CONVERTER = BuiltInConverter.of(6,
newTrimmingConverter(newEmptyValueConverter(value -> {
Expand Down

0 comments on commit 6d64c6f

Please sign in to comment.