Skip to content

Commit

Permalink
Support for JDK21
Browse files Browse the repository at this point in the history
Motivation:
JDK21 GA has been released

Modification:
Add JDK 21 environment

Result:
Ensures compatibility with JDK21
  • Loading branch information
jchrys committed Oct 6, 2023
1 parent 2a4e463 commit 68de157
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
java-version: [ 8, 11, 17 ]
java-version: [ 8, 11, 17 , 21]
name: linux-java-${{ matrix.java-version }}
steps:
- uses: actions/checkout@v3
- name: Set up Java ${{ matrix.java-version }}
uses: actions/setup-java@v3
with:
distribution: temurin
distribution: zulu
java-version: ${{ matrix.java-version }}
cache: maven
- name: Unit test with Maven
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/io/asyncer/r2dbc/mysql/codec/DefaultCodecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.r2dbc.spi.Parameter;
import org.jetbrains.annotations.Nullable;

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

static final class Builder extends ArrayList<Codec<?>> implements CodecsBuilder {
static final class Builder implements CodecsBuilder {

private final ByteBufAllocator allocator;

@GuardedBy("this")
private final ArrayList<Codec<?>> codecs = new ArrayList<>();

Builder(ByteBufAllocator allocator) {
this.allocator = allocator;
}

@Override
public CodecsBuilder addFirst(Codec<?> codec) {
synchronized (this) {
if (isEmpty()) {
Codec<?>[] codecs = defaultCodecs(allocator);
if (codecs.isEmpty()) {
Codec<?>[] defaultCodecs = defaultCodecs(allocator);

ensureCapacity(codecs.length + 1);
codecs.ensureCapacity(defaultCodecs.length + 1);
// Add first.
add(codec);
addAll(InternalArrays.asImmutableList(codecs));
codecs.add(codec);
codecs.addAll(InternalArrays.asImmutableList(defaultCodecs));
} else {
add(0, codec);
codecs.add(0, codec);
}
}
return this;
Expand All @@ -342,10 +346,10 @@ public CodecsBuilder addFirst(Codec<?> codec) {
@Override
public CodecsBuilder addLast(Codec<?> codec) {
synchronized (this) {
if (isEmpty()) {
addAll(InternalArrays.asImmutableList(defaultCodecs(allocator)));
if (codecs.isEmpty()) {
codecs.addAll(InternalArrays.asImmutableList(defaultCodecs(allocator)));
}
add(codec);
codecs.add(codec);
}
return this;
}
Expand All @@ -354,13 +358,13 @@ public CodecsBuilder addLast(Codec<?> codec) {
public Codecs build() {
synchronized (this) {
try {
if (isEmpty()) {
if (codecs.isEmpty()) {
return new DefaultCodecs(defaultCodecs(allocator));
}
return new DefaultCodecs(toArray(new Codec<?>[0]));
return new DefaultCodecs(codecs.toArray(new Codec<?>[0]));
} finally {
clear();
trimToSize();
codecs.clear();
codecs.trimToSize();
}
}
}
Expand Down

0 comments on commit 68de157

Please sign in to comment.