Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for JDK21 #150

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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