@@ -147,7 +147,7 @@ public static void checkArgument(@Nonnull boolean expression, @Nonnull Eid eid)
147
147
* @param expression a boolean expression
148
148
* @param eid the exception message to use if the check fails; will be converted to a string using
149
149
* {@link String#valueOf(Object)}
150
- * @throws IllegalStateException if {@code expression} is false
150
+ * @throws EidIllegalStateException if {@code expression} is false
151
151
*/
152
152
public static void checkState (@ Nonnull boolean expression , @ Nonnull String eid ) {
153
153
String checkedEid = checkNotNull (eid );
@@ -163,7 +163,7 @@ public static void checkState(@Nonnull boolean expression, @Nonnull String eid)
163
163
* @param expression a boolean expression
164
164
* @param eid the exception message to use if the check fails; will be converted to a string using
165
165
* {@link String#valueOf(Object)}
166
- * @throws IllegalStateException if {@code expression} is false
166
+ * @throws EidIllegalStateException if {@code expression} is false
167
167
*/
168
168
public static void checkState (@ Nonnull boolean expression , @ Nonnull Eid eid ) {
169
169
Eid checkedEid = checkNotNull (eid );
@@ -180,7 +180,7 @@ public static void checkState(@Nonnull boolean expression, @Nonnull Eid eid) {
180
180
* @param eid the exception message to use if the check fails; will be converted to a string using
181
181
* {@link String#valueOf(Object)}
182
182
* @return the non-null reference that was validated
183
- * @throws NullPointerException if {@code reference} is null
183
+ * @throws EidNullPointerException if {@code reference} is null
184
184
*/
185
185
@ Nonnull
186
186
public static <T > T checkNotNull (@ Nullable T reference , @ Nonnull String eid ) {
@@ -199,7 +199,7 @@ public static <T> T checkNotNull(@Nullable T reference, @Nonnull String eid) {
199
199
* @param eid the exception message to use if the check fails; will be converted to a string using
200
200
* {@link String#valueOf(Object)}
201
201
* @return the non-null reference that was validated
202
- * @throws NullPointerException if {@code reference} is null
202
+ * @throws EidNullPointerException if {@code reference} is null
203
203
*/
204
204
@ Nonnull
205
205
public static <T > T checkNotNull (@ Nullable T reference , @ Nonnull Eid eid ) {
@@ -218,12 +218,15 @@ public static <T> T checkNotNull(@Nullable T reference, @Nonnull Eid eid) {
218
218
* @param size the size of that array, list or string
219
219
* @param eid the text to use to describe this index in an error message
220
220
* @return the value of {@code index}
221
- * @throws IndexOutOfBoundsException if {@code index} is negative or is not less than {@code size}
222
- * @throws IllegalArgumentException if {@code size} is negative
221
+ * @throws EidIndexOutOfBoundsException if {@code index} is negative or is not less than {@code size}
222
+ * @throws EidIllegalArgumentException if {@code size} is negative
223
223
*/
224
224
@ Nonnull
225
225
public static int checkElementIndex (int index , int size , @ Nonnull String eid ) {
226
226
String checkedEid = checkNotNull (eid );
227
+ if (size < 0 ) {
228
+ throw new EidIllegalArgumentException (new Eid (checkedEid ));
229
+ }
227
230
// Carefully optimized for execution by hotspot (explanatory comment above)
228
231
if (index < 0 || index > size ) {
229
232
throw new EidIndexOutOfBoundsException (new Eid (checkedEid ));
@@ -239,12 +242,15 @@ public static int checkElementIndex(int index, int size, @Nonnull String eid) {
239
242
* @param size the size of that array, list or string
240
243
* @param eid the text to use to describe this index in an error message
241
244
* @return the value of {@code index}
242
- * @throws IndexOutOfBoundsException if {@code index} is negative or is not less than {@code size}
243
- * @throws IllegalArgumentException if {@code size} is negative
245
+ * @throws EidIndexOutOfBoundsException if {@code index} is negative or is not less than {@code size}
246
+ * @throws EidIllegalArgumentException if {@code size} is negative
244
247
*/
245
248
@ Nonnull
246
249
public static int checkElementIndex (int index , int size , @ Nonnull Eid eid ) {
247
250
Eid checkedEid = checkNotNull (eid );
251
+ if (size < 0 ) {
252
+ throw new EidIllegalArgumentException (checkedEid );
253
+ }
248
254
// Carefully optimized for execution by hotspot (explanatory comment above)
249
255
if (index < 0 || index > size ) {
250
256
throw new EidIndexOutOfBoundsException (checkedEid );
@@ -272,6 +278,7 @@ public static int checkElementIndex(int index, int size, @Nonnull Eid eid) {
272
278
* @param code code to be executed within a try-catch block
273
279
* @param eid uniq developer identifier from date for ex.: "20150716:123200"
274
280
* @return A block of code return type, if exception is not thrown
281
+ * @throws EidRuntimeException if code block thrown any exception, which in that case is wrapped in EidRuntimeException
275
282
*/
276
283
@ Nullable
277
284
@ SuppressWarnings ({
@@ -307,6 +314,7 @@ public static <R> R tryToExecute(@Nonnull RiskyCode<R> code, @Nonnull String eid
307
314
* @param code code to be executed within a try-catch block
308
315
* @param eid uniq developer identifier from date for ex.: "20150716:123200"
309
316
* @return A block of code return type, if exception is not thrown
317
+ * @throws EidRuntimeException if code block thrown any exception, which in that case is wrapped in EidRuntimeException
310
318
*/
311
319
@ Nullable
312
320
@ SuppressWarnings ({
@@ -344,7 +352,7 @@ public interface RiskyCode<R> {
344
352
345
353
private static <T > T checkNotNull (@ Nullable T reference ) {
346
354
if (reference == null ) {
347
- throw new IllegalArgumentException (new NullPointerException ( "Pass not-null Eid to EidPreconditions first!" ) );
355
+ throw new IllegalArgumentException ("Pass not-null Eid to EidPreconditions first!" );
348
356
}
349
357
return reference ;
350
358
}
0 commit comments