Skip to content

Commit 67c1ca6

Browse files
committed
Bugfix #15: proper checking for index and size for arrays
1 parent bac4170 commit 67c1ca6

16 files changed

+68
-155
lines changed

src/main/java/pl/wavesoftware/eid/exceptions/EidIllegalArgumentException.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,4 @@ public EidIllegalArgumentException(Eid id, @Nullable Throwable cause) {
205205
super(id, cause);
206206
}
207207

208-
/**
209-
* @return {@link IllegalArgumentException} class
210-
*/
211-
@Override
212-
public Class<? extends RuntimeException> getJavaClass() {
213-
return IllegalArgumentException.class;
214-
}
215-
216208
}

src/main/java/pl/wavesoftware/eid/exceptions/EidIllegalStateException.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,4 @@ public EidIllegalStateException(Eid id, @Nullable Throwable cause) {
219219
super(id, cause);
220220
}
221221

222-
/**
223-
* @return {@link IllegalStateException} class
224-
*/
225-
@Override
226-
public Class<? extends RuntimeException> getJavaClass() {
227-
return IllegalStateException.class;
228-
}
229-
230222
}

src/main/java/pl/wavesoftware/eid/exceptions/EidIndexOutOfBoundsException.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,4 @@ public EidIndexOutOfBoundsException(
222222
super(id, cause);
223223
}
224224

225-
226-
/**
227-
* @return {@link IndexOutOfBoundsException} class
228-
*/
229-
@Override
230-
public Class<? extends RuntimeException> getJavaClass() {
231-
return IndexOutOfBoundsException.class;
232-
}
233-
234225
}

src/main/java/pl/wavesoftware/eid/exceptions/EidNullPointerException.java

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ public EidNullPointerException(EidMessage message) {
9494
* {@link #getCause()} method). (A <tt>null</tt> value is
9595
* permitted, and indicates that the cause is nonexistent or
9696
*/
97-
public EidNullPointerException(
98-
CharSequence eid,
99-
String message,
100-
@Nullable Throwable cause
101-
) {
97+
public EidNullPointerException(CharSequence eid, String message, @Nullable Throwable cause) {
10298
super(eid, message, cause);
10399
}
104100

@@ -117,10 +113,7 @@ public EidNullPointerException(
117113
* {@link #getCause()} method). (A <tt>null</tt> value is
118114
* permitted, and indicates that the cause is nonexistent or
119115
*/
120-
public EidNullPointerException(
121-
EidMessage message,
122-
@Nullable Throwable cause
123-
) {
116+
public EidNullPointerException(EidMessage message, @Nullable Throwable cause) {
124117
super(message, cause);
125118
}
126119

@@ -140,10 +133,7 @@ public EidNullPointerException(
140133
* {@link #getCause()} method). (A <tt>null</tt> value is
141134
* permitted, and indicates that the cause is nonexistent or
142135
*/
143-
public EidNullPointerException(
144-
CharSequence eid,
145-
@Nullable Throwable cause
146-
) {
136+
public EidNullPointerException(CharSequence eid, @Nullable Throwable cause) {
147137
super(eid, cause);
148138
}
149139

@@ -191,11 +181,7 @@ public EidNullPointerException(Eid id, String message) {
191181
* {@link #getCause()} method). (A <tt>null</tt> value is
192182
* permitted, and indicates that the cause is nonexistent or
193183
*/
194-
public EidNullPointerException(
195-
Eid id,
196-
String message,
197-
@Nullable Throwable cause
198-
) {
184+
public EidNullPointerException(Eid id, String message, @Nullable Throwable cause) {
199185
super(id, message, cause);
200186
}
201187

@@ -215,19 +201,8 @@ public EidNullPointerException(
215201
* {@link #getCause()} method). (A <tt>null</tt> value is
216202
* permitted, and indicates that the cause is nonexistent or
217203
*/
218-
public EidNullPointerException(
219-
Eid id,
220-
@Nullable Throwable cause
221-
) {
204+
public EidNullPointerException(Eid id, @Nullable Throwable cause) {
222205
super(id, cause);
223206
}
224207

225-
/**
226-
* @return {@link NullPointerException} class
227-
*/
228-
@Override
229-
public Class<? extends RuntimeException> getJavaClass() {
230-
return NullPointerException.class;
231-
}
232-
233208
}

src/main/java/pl/wavesoftware/eid/exceptions/EidRuntimeException.java

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ public EidRuntimeException(CharSequence eid) {
7575
* @param message the detail message. The detail message is saved for
7676
* later retrieval by the {@link #getMessage()} method.
7777
*/
78-
public EidRuntimeException(
79-
CharSequence eid,
80-
String message
81-
) {
78+
public EidRuntimeException(CharSequence eid, String message) {
8279
this(new Eid(eid), message);
8380
}
8481

@@ -91,9 +88,7 @@ public EidRuntimeException(
9188
* @param message the Eid message. The detail message is saved for
9289
* later retrieval by the {@link #getMessage()} method.
9390
*/
94-
public EidRuntimeException(
95-
EidMessage message
96-
) {
91+
public EidRuntimeException(EidMessage message) {
9792
super(message.toString());
9893
this.eid = message.getEid();
9994
}
@@ -115,11 +110,7 @@ public EidRuntimeException(
115110
* permitted, and indicates that the cause is nonexistent or
116111
* unknown.)
117112
*/
118-
public EidRuntimeException(
119-
CharSequence eid,
120-
String message,
121-
@Nullable Throwable cause
122-
) {
113+
public EidRuntimeException(CharSequence eid, String message, @Nullable Throwable cause) {
123114
this(new Eid(eid), message, cause);
124115
}
125116

@@ -139,10 +130,7 @@ public EidRuntimeException(
139130
* permitted, and indicates that the cause is nonexistent or
140131
* unknown.)
141132
*/
142-
public EidRuntimeException(
143-
EidMessage message,
144-
@Nullable Throwable cause
145-
) {
133+
public EidRuntimeException(EidMessage message, @Nullable Throwable cause) {
146134
this(message.getEid(), message.toString(), cause);
147135
}
148136

@@ -163,10 +151,7 @@ public EidRuntimeException(
163151
* permitted, and indicates that the cause is nonexistent or
164152
* unknown.)
165153
*/
166-
public EidRuntimeException(
167-
CharSequence eid,
168-
@Nullable Throwable cause
169-
) {
154+
public EidRuntimeException(CharSequence eid, @Nullable Throwable cause) {
170155
this(new Eid(eid), cause);
171156
}
172157

@@ -195,10 +180,7 @@ public EidRuntimeException(Eid id) {
195180
* @param message the detail message. The detail message is saved for
196181
* later retrieval by the {@link #getMessage()} method.
197182
*/
198-
public EidRuntimeException(
199-
Eid id,
200-
String message
201-
) {
183+
public EidRuntimeException(Eid id, String message) {
202184
super(id.message(message).toString());
203185
this.eid = id;
204186
}
@@ -220,11 +202,7 @@ public EidRuntimeException(
220202
* permitted, and indicates that the cause is nonexistent or
221203
* unknown.)
222204
*/
223-
public EidRuntimeException(
224-
Eid id,
225-
String message,
226-
@Nullable Throwable cause
227-
) {
205+
public EidRuntimeException(Eid id, String message, @Nullable Throwable cause) {
228206
super(id.message(message).toString(), cause);
229207
this.eid = id;
230208
}
@@ -246,10 +224,7 @@ public EidRuntimeException(
246224
* permitted, and indicates that the cause is nonexistent or
247225
* unknown.)
248226
*/
249-
public EidRuntimeException(
250-
Eid id,
251-
@Nullable Throwable cause
252-
) {
227+
public EidRuntimeException(Eid id, @Nullable Throwable cause) {
253228
super(messageOf(id, cause), cause);
254229
eid = id;
255230
}
@@ -259,17 +234,6 @@ public Eid getEid() {
259234
return eid;
260235
}
261236

262-
/**
263-
* Returns a standard JDK class that this ones is base on. It doesn't mean
264-
* this class do extends that class, but it might.
265-
*
266-
* @return a standard JDK class of exception, in this case
267-
* {@link RuntimeException} class.
268-
*/
269-
public Class<? extends RuntimeException> getJavaClass() {
270-
return RuntimeException.class;
271-
}
272-
273237
private static String messageOf(Eid eid, @Nullable Throwable cause) {
274238
if (cause != null) {
275239
return eid.message(messageOf(cause)).toString();

src/main/java/pl/wavesoftware/eid/impl/BindingImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ public EidMessage createEidMessage(
5454

5555
@Override
5656
public <T extends Serializable> SerializableSupplier<T> lazy(Supplier<T> supplier) {
57-
return SerializableLazy.of(supplier);
57+
return SerializableLazy.serializableOf(supplier);
5858
}
5959
}

src/main/java/pl/wavesoftware/eid/impl/EidTextRepresentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class EidTextRepresentation implements EidContainer, Serializable {
4040
) {
4141
this.eid = eid;
4242
this.textMessage = textMessage;
43-
this.actual = SerializableLazy.of(new Supplier<String>() {
43+
this.actual = SerializableLazy.serializableOf(new Supplier<String>() {
4444
@Override
4545
public String get() {
4646
return configuration.getFormatter()

src/main/java/pl/wavesoftware/eid/impl/SerializableLazy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private SerializableLazy(Supplier<T> supplier) {
3535
super(supplier);
3636
}
3737

38-
static <R extends Serializable> SerializableLazy<R> of(Supplier<R> supplier) {
38+
static <R extends Serializable> SerializableLazy<R> serializableOf(Supplier<R> supplier) {
3939
return new SerializableLazy<R>(supplier);
4040
}
4141

src/main/java/pl/wavesoftware/eid/impl/TextMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class TextMessage implements Serializable {
3434
CharSequence messageFormat,
3535
Object[] arguments
3636
) {
37-
message = SerializableLazy.of(new MessageSupplier(
37+
message = SerializableLazy.serializableOf(new MessageSupplier(
3838
configuration, messageFormat, arguments
3939
));
4040
}

src/main/java/pl/wavesoftware/eid/utils/EidPreconditions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public static int checkElementIndex(
541541
}
542542

543543
private static boolean isIndexAndSizeIllegal(int index, int size) {
544-
return index < 0 || index > size;
544+
return index < 0 || index >= size;
545545
}
546546

547547
private static boolean isSizeIllegal(int size) {

0 commit comments

Comments
 (0)