Skip to content

Commit 69876ae

Browse files
authored
Support for JDK21 (#150)
Motivation: JDK21 GA has been released Modification: Add JDK 21 environment Result: Ensures compatibility with JDK21
1 parent 2a4e463 commit 69876ae

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

.github/workflows/ci-unit-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ jobs:
99
runs-on: ubuntu-20.04
1010
strategy:
1111
matrix:
12-
java-version: [ 8, 11, 17 ]
12+
java-version: [ 8, 11, 17 , 21]
1313
name: linux-java-${{ matrix.java-version }}
1414
steps:
1515
- uses: actions/checkout@v3
1616
- name: Set up Java ${{ matrix.java-version }}
1717
uses: actions/setup-java@v3
1818
with:
19-
distribution: temurin
19+
distribution: zulu
2020
java-version: ${{ matrix.java-version }}
2121
cache: maven
2222
- name: Unit test with Maven

src/main/java/io/asyncer/r2dbc/mysql/codec/DefaultCodecs.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.r2dbc.spi.Parameter;
2727
import org.jetbrains.annotations.Nullable;
2828

29+
import javax.annotation.concurrent.GuardedBy;
2930
import java.lang.reflect.ParameterizedType;
3031
import java.lang.reflect.Type;
3132
import java.math.BigInteger;
@@ -314,26 +315,29 @@ private static Codec<?>[] defaultCodecs(ByteBufAllocator allocator) {
314315
};
315316
}
316317

317-
static final class Builder extends ArrayList<Codec<?>> implements CodecsBuilder {
318+
static final class Builder implements CodecsBuilder {
318319

319320
private final ByteBufAllocator allocator;
320321

322+
@GuardedBy("this")
323+
private final ArrayList<Codec<?>> codecs = new ArrayList<>();
324+
321325
Builder(ByteBufAllocator allocator) {
322326
this.allocator = allocator;
323327
}
324328

325329
@Override
326330
public CodecsBuilder addFirst(Codec<?> codec) {
327331
synchronized (this) {
328-
if (isEmpty()) {
329-
Codec<?>[] codecs = defaultCodecs(allocator);
332+
if (codecs.isEmpty()) {
333+
Codec<?>[] defaultCodecs = defaultCodecs(allocator);
330334

331-
ensureCapacity(codecs.length + 1);
335+
codecs.ensureCapacity(defaultCodecs.length + 1);
332336
// Add first.
333-
add(codec);
334-
addAll(InternalArrays.asImmutableList(codecs));
337+
codecs.add(codec);
338+
codecs.addAll(InternalArrays.asImmutableList(defaultCodecs));
335339
} else {
336-
add(0, codec);
340+
codecs.add(0, codec);
337341
}
338342
}
339343
return this;
@@ -342,10 +346,10 @@ public CodecsBuilder addFirst(Codec<?> codec) {
342346
@Override
343347
public CodecsBuilder addLast(Codec<?> codec) {
344348
synchronized (this) {
345-
if (isEmpty()) {
346-
addAll(InternalArrays.asImmutableList(defaultCodecs(allocator)));
349+
if (codecs.isEmpty()) {
350+
codecs.addAll(InternalArrays.asImmutableList(defaultCodecs(allocator)));
347351
}
348-
add(codec);
352+
codecs.add(codec);
349353
}
350354
return this;
351355
}
@@ -354,13 +358,13 @@ public CodecsBuilder addLast(Codec<?> codec) {
354358
public Codecs build() {
355359
synchronized (this) {
356360
try {
357-
if (isEmpty()) {
361+
if (codecs.isEmpty()) {
358362
return new DefaultCodecs(defaultCodecs(allocator));
359363
}
360-
return new DefaultCodecs(toArray(new Codec<?>[0]));
364+
return new DefaultCodecs(codecs.toArray(new Codec<?>[0]));
361365
} finally {
362-
clear();
363-
trimToSize();
366+
codecs.clear();
367+
codecs.trimToSize();
364368
}
365369
}
366370
}

0 commit comments

Comments
 (0)