Elffuss BraidHub

kikocis/java-driver public

Throw IllegalArgumentException consistently

This commit changes all places where an IllegalStateException was
thrown to throw an IllegalArgumentException instead.
Changeset9483a61dd223b1de0e512fa2c92f3597dd7b91e49b2a0dd13ddbd2dc2208f7e4
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2016-07-12 11:46 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2016-07-22 09:47 -07:00
Parents37e876ef1735

Browse the files at this changeset

4 files changed

modified driver-mapping/src/main/java/com/datastax/driver/mapping/AnnotationParser.java +1 −1
@@ -253,7 +253,7 @@
253253 fetchSize = options.fetchSize();
254254 tracing = options.tracing();
255255 if (options.idempotent().length > 1) {
256- throw new IllegalStateException("idemtpotence() attribute can only accept one value");
256+ throw new IllegalArgumentException("idemtpotence() attribute can only accept one value");
257257 }
258258 idempotent = options.idempotent().length == 0 ? null : options.idempotent()[0];
259259 }
modified driver-mapping/src/main/java/com/datastax/driver/mapping/PropertyMapper.java +5 −5
@@ -28,7 +28,7 @@
2828 import java.util.Collection;
2929 import java.util.Map;
3030
31-import static com.google.common.base.Preconditions.checkState;
31+import static com.google.common.base.Preconditions.checkArgument;
3232
3333 /**
3434 * Maps a Java bean property to a table column or a UDT field.
@@ -65,9 +65,9 @@
6565 if (setter != null)
6666 ReflectionUtils.tryMakeAccessible(setter);
6767 if (!isTransient()) {
68- checkState((field != null && field.isAccessible()) || (getter != null && getter.isAccessible()),
68+ checkArgument((field != null && field.isAccessible()) || (getter != null && getter.isAccessible()),
6969 "Property '%s' is not readable", propertyName);
70- checkState((field != null && field.isAccessible()) || (setter != null && setter.isAccessible()),
70+ checkArgument((field != null && field.isAccessible()) || (setter != null && setter.isAccessible()),
7171 "Property '%s' is not writable", propertyName);
7272 }
7373 columnName = inferColumnName();
@@ -84,7 +84,7 @@
8484 else
8585 return field.get(entity);
8686 } catch (Exception e) {
87- throw new IllegalStateException("Unable to read property '" + propertyName + "' in " + entity.getClass().getName(), e);
87+ throw new IllegalArgumentException("Unable to read property '" + propertyName + "' in " + entity.getClass(), e);
8888 }
8989 }
9090
@@ -96,7 +96,7 @@
9696 else
9797 field.set(entity, value);
9898 } catch (Exception e) {
99- throw new IllegalStateException("Unable to write property '" + propertyName + "' in " + entity.getClass().getName(), e);
99+ throw new IllegalArgumentException("Unable to write property '" + propertyName + "' in " + entity.getClass(), e);
100100 }
101101 }
102102
modified driver-mapping/src/main/java/com/datastax/driver/mapping/ReflectionUtils.java +1 −1
@@ -48,7 +48,7 @@
4848 try {
4949 return publicConstructor.newInstance();
5050 } catch (Exception e) {
51- throw new IllegalStateException("Can't create an instance of " + clazz, e);
51+ throw new IllegalArgumentException("Can't create an instance of " + clazz, e);
5252 }
5353 }
5454
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperInvalidAnnotationsTest.java +2 −2
@@ -261,7 +261,7 @@
261261
262262 }
263263
264- @Test(groups = "unit", expectedExceptions = IllegalStateException.class,
264+ @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class,
265265 expectedExceptionsMessageRegExp =
266266 "Property 'notReadable' is not readable")
267267 public void should_not_allow_unreadable_property() throws Exception {
@@ -277,7 +277,7 @@
277277
278278 }
279279
280- @Test(groups = "unit", expectedExceptions = IllegalStateException.class,
280+ @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class,
281281 expectedExceptionsMessageRegExp =
282282 "Property 'notWritable' is not writable")
283283 public void should_not_allow_unwritable_property() throws Exception {