Skip to content

Commit

Permalink
fix: "Required class information missing" when old org.jboss:jandex p…
Browse files Browse the repository at this point in the history
…arses pgjdbc classes (PR #2010)
  • Loading branch information
vlsi committed Jan 10, 2021
1 parent c57ac5e commit 2df6c97
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 39 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ jobs:
S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }}
with:
job-id: jdk8
arguments: autostyleCheck checkstyleAll
arguments: autostyleCheck checkstyleAll jandex

ubuntu-latest:
name: 'Ubuntu, PG latest (JDK 8)'
name: 'Ubuntu, PG latest (JDK ${{ matrix.jdk }})'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
jdk: [8, 11]
# Service must be started after checkout, because we want to use git-stored files for initialization
# of the Docker container. So we start it with and explicit docker ... command
# services:
Expand Down Expand Up @@ -63,10 +67,10 @@ jobs:
- name: Start PostgreSQL
working-directory: docker
run: docker-compose up -d && docker-compose logs
- name: 'Set up JDK 8'
- name: 'Set up JDK ${{ matrix.jdk }}'
uses: actions/setup-java@v1
with:
java-version: 8
java-version: ${{ matrix.jdk }}
- name: Prepare ssltest.local.properties
run: echo enable_ssl_tests=true > ssltest.local.properties
- uses: burrunan/gradle-cache-action@v1
Expand All @@ -76,7 +80,7 @@ jobs:
S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }}
with:
job-id: jdk${{ matrix.jdk }}
arguments: --scan --no-parallel --no-daemon test
arguments: --scan --no-parallel --no-daemon jandex test
properties: |
skipReplicationTests=
port=${{ job.services.postgres.ports['5432'] }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Verify code via forbidden-apis (jdk-internal and jdk-non-portable signatures) [PR #2012](https://github.com/pgjdbc/pgjdbc/pull/2012)

### Fixed
- Fix "Required class information missing" when old org.jboss:jandex parses pgjdbc classes [issue 2008][https://github.com/pgjdbc/pgjdbc/issues/2008]

## [42.2.18]
### Fixed
Expand Down
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ plugins {
id("com.github.johnrengelman.shadow") apply false
id("de.thetaphi.forbiddenapis") apply false
id("org.nosphere.gradle.github.actions")
id("com.github.vlsi.jandex") apply false
// IDE configuration
id("org.jetbrains.gradle.plugin.idea-ext")
id("com.github.vlsi.ide")
Expand Down Expand Up @@ -370,8 +371,13 @@ allprojects {

val sourceSets: SourceSetContainer by project

apply(plugin = "com.github.vlsi.jandex")
apply(plugin = "maven-publish")

project.configure<com.github.vlsi.jandex.JandexExtension> {
skipIndexFileGeneration()
}

if (!enableGradleMetadata) {
tasks.withType<GenerateModuleMetadata> {
enabled = false
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ com.github.burrunan.s3-build-cache.version=1.1
com.github.johnrengelman.shadow.version=5.1.0
com.github.lburgazzoli.karaf.version=0.5.1
com.github.spotbugs.version=2.0.0
com.github.vlsi.vlsi-release-plugins.version=1.70
com.github.vlsi.vlsi-release-plugins.version=1.71
de.thetaphi.forbiddenapis.version=3.1
kotlin.version=1.3.70
me.champeau.gradle.jmh.version=0.5.0
Expand Down
45 changes: 22 additions & 23 deletions pgjdbc/src/main/java/org/postgresql/jdbc/ArrayEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.postgresql.util.PSQLState;

import org.checkerframework.checker.index.qual.Positive;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -111,7 +110,7 @@ byte[] toBinaryRepresentation(BaseConnection connection, A array, int oid)
* @param <A>
* Base array type supported.
*/
private abstract static class AbstractArrayEncoder<A extends @NonNull Object>
private abstract static class AbstractArrayEncoder<A extends Object>
implements ArrayEncoder<A> {

private final int oid;
Expand Down Expand Up @@ -222,7 +221,7 @@ public boolean supportBinaryRepresentation(int oid) {
* @param <N>
* The base type of array.
*/
private abstract static class NumberArrayEncoder<N extends Number> extends AbstractArrayEncoder<N @NonNull []> {
private abstract static class NumberArrayEncoder<N extends Number> extends AbstractArrayEncoder<N[]> {

private final int fieldSize;

Expand Down Expand Up @@ -353,7 +352,7 @@ final void appendArray(StringBuilder sb, char delim, N[] array) {
* @param <A>
* The primitive array to support.
*/
private abstract static class FixedSizePrimitiveArrayEncoder<A extends @NonNull Object>
private abstract static class FixedSizePrimitiveArrayEncoder<A extends Object>
extends AbstractArrayEncoder<A> {

private final int fieldSize;
Expand Down Expand Up @@ -430,7 +429,7 @@ final byte[] toSingleDimensionBinaryRepresentation(BaseConnection connection, A
protected abstract void write(A array, byte[] bytes, int offset);
}

private static final AbstractArrayEncoder<long @NonNull []> LONG_ARRAY = new FixedSizePrimitiveArrayEncoder<long @NonNull []>(8, Oid.INT8,
private static final AbstractArrayEncoder<long[]> LONG_ARRAY = new FixedSizePrimitiveArrayEncoder<long[]>(8, Oid.INT8,
Oid.INT8_ARRAY) {

/**
Expand Down Expand Up @@ -462,7 +461,7 @@ protected void write(long[] array, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<Long @NonNull []> LONG_OBJ_ARRAY = new NumberArrayEncoder<Long>(8, Oid.INT8,
private static final AbstractArrayEncoder<Long[]> LONG_OBJ_ARRAY = new NumberArrayEncoder<Long>(8, Oid.INT8,
Oid.INT8_ARRAY) {

@Override
Expand All @@ -471,7 +470,7 @@ protected void write(Long number, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<int @NonNull []> INT_ARRAY = new FixedSizePrimitiveArrayEncoder<int @NonNull []>(4, Oid.INT4,
private static final AbstractArrayEncoder<int[]> INT_ARRAY = new FixedSizePrimitiveArrayEncoder<int[]>(4, Oid.INT4,
Oid.INT4_ARRAY) {

/**
Expand Down Expand Up @@ -503,7 +502,7 @@ protected void write(int[] array, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<Integer @NonNull []> INT_OBJ_ARRAY = new NumberArrayEncoder<Integer>(4, Oid.INT4,
private static final AbstractArrayEncoder<Integer[]> INT_OBJ_ARRAY = new NumberArrayEncoder<Integer>(4, Oid.INT4,
Oid.INT4_ARRAY) {

@Override
Expand All @@ -512,7 +511,7 @@ protected void write(Integer number, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<short @NonNull []> SHORT_ARRAY = new FixedSizePrimitiveArrayEncoder<short @NonNull []>(2,
private static final AbstractArrayEncoder<short[]> SHORT_ARRAY = new FixedSizePrimitiveArrayEncoder<short[]>(2,
Oid.INT2, Oid.INT2_ARRAY) {

/**
Expand Down Expand Up @@ -544,7 +543,7 @@ protected void write(short[] array, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<Short @NonNull []> SHORT_OBJ_ARRAY = new NumberArrayEncoder<Short>(2, Oid.INT2,
private static final AbstractArrayEncoder<Short[]> SHORT_OBJ_ARRAY = new NumberArrayEncoder<Short>(2, Oid.INT2,
Oid.INT2_ARRAY) {

/**
Expand All @@ -556,7 +555,7 @@ protected void write(Short number, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<double @NonNull []> DOUBLE_ARRAY = new FixedSizePrimitiveArrayEncoder<double @NonNull []>(8,
private static final AbstractArrayEncoder<double[]> DOUBLE_ARRAY = new FixedSizePrimitiveArrayEncoder<double[]>(8,
Oid.FLOAT8, Oid.FLOAT8_ARRAY) {

/**
Expand Down Expand Up @@ -591,7 +590,7 @@ protected void write(double[] array, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<Double @NonNull []> DOUBLE_OBJ_ARRAY = new NumberArrayEncoder<Double>(8, Oid.FLOAT8,
private static final AbstractArrayEncoder<Double[]> DOUBLE_OBJ_ARRAY = new NumberArrayEncoder<Double>(8, Oid.FLOAT8,
Oid.FLOAT8_ARRAY) {

/**
Expand All @@ -603,7 +602,7 @@ protected void write(Double number, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<float @NonNull []> FLOAT_ARRAY = new FixedSizePrimitiveArrayEncoder<float @NonNull []>(4,
private static final AbstractArrayEncoder<float[]> FLOAT_ARRAY = new FixedSizePrimitiveArrayEncoder<float[]>(4,
Oid.FLOAT4, Oid.FLOAT4_ARRAY) {

/**
Expand Down Expand Up @@ -638,7 +637,7 @@ protected void write(float[] array, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<Float @NonNull []> FLOAT_OBJ_ARRAY = new NumberArrayEncoder<Float>(4, Oid.FLOAT4,
private static final AbstractArrayEncoder<Float[]> FLOAT_OBJ_ARRAY = new NumberArrayEncoder<Float>(4, Oid.FLOAT4,
Oid.FLOAT4_ARRAY) {

/**
Expand All @@ -650,7 +649,7 @@ protected void write(Float number, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<boolean @NonNull []> BOOLEAN_ARRAY = new FixedSizePrimitiveArrayEncoder<boolean @NonNull []>(1,
private static final AbstractArrayEncoder<boolean[]> BOOLEAN_ARRAY = new FixedSizePrimitiveArrayEncoder<boolean[]>(1,
Oid.BOOL, Oid.BOOL_ARRAY) {

/**
Expand Down Expand Up @@ -682,7 +681,7 @@ protected void write(boolean[] array, byte[] bytes, int offset) {
}
};

private static final AbstractArrayEncoder<Boolean @NonNull []> BOOLEAN_OBJ_ARRAY = new AbstractArrayEncoder<Boolean @NonNull []>(Oid.BOOL,
private static final AbstractArrayEncoder<Boolean[]> BOOLEAN_OBJ_ARRAY = new AbstractArrayEncoder<Boolean[]>(Oid.BOOL,
Oid.BOOL_ARRAY) {

/**
Expand Down Expand Up @@ -765,7 +764,7 @@ void appendArray(StringBuilder sb, char delim, Boolean[] array) {
}
};

private static final AbstractArrayEncoder<String @NonNull []> STRING_ARRAY = new AbstractArrayEncoder<String @NonNull []>(Oid.VARCHAR,
private static final AbstractArrayEncoder<String[]> STRING_ARRAY = new AbstractArrayEncoder<String[]>(Oid.VARCHAR,
Oid.VARCHAR_ARRAY) {

/**
Expand Down Expand Up @@ -922,7 +921,7 @@ byte[] toSingleDimensionBinaryRepresentation(BaseConnection connection, String[]
}
};

private static final AbstractArrayEncoder<byte[] @NonNull []> BYTEA_ARRAY = new AbstractArrayEncoder<byte[] @NonNull []>(Oid.BYTEA,
private static final AbstractArrayEncoder<byte[][]> BYTEA_ARRAY = new AbstractArrayEncoder<byte[][]>(Oid.BYTEA,
Oid.BYTEA_ARRAY) {

/**
Expand Down Expand Up @@ -1043,7 +1042,7 @@ void appendArray(StringBuilder sb, char delim, byte[][] array) {
}
};

private static final AbstractArrayEncoder<Object @NonNull []> OBJECT_ARRAY = new AbstractArrayEncoder<Object @NonNull []>(0, 0) {
private static final AbstractArrayEncoder<Object[]> OBJECT_ARRAY = new AbstractArrayEncoder<Object[]>(0, 0) {

@Override
public int getDefaultArrayTypeOid() {
Expand Down Expand Up @@ -1088,7 +1087,7 @@ void appendArray(StringBuilder sb, char delim, Object[] array) {
};

@SuppressWarnings("rawtypes")
private static final Map<@NonNull Class, @NonNull AbstractArrayEncoder> ARRAY_CLASS_TO_ENCODER = new HashMap<@NonNull Class, @NonNull AbstractArrayEncoder>(
private static final Map<Class, AbstractArrayEncoder> ARRAY_CLASS_TO_ENCODER = new HashMap<Class, AbstractArrayEncoder>(
(int) (14 / .75) + 1);

static {
Expand Down Expand Up @@ -1120,7 +1119,7 @@ void appendArray(StringBuilder sb, char delim, Object[] array) {
* @see ArrayEncoding.ArrayEncoder#supportBinaryRepresentation(int)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <A extends @NonNull Object> ArrayEncoder<A> getArrayEncoder(A array) throws PSQLException {
public static <A extends Object> ArrayEncoder<A> getArrayEncoder(A array) throws PSQLException {
final Class<?> arrayClazz = array.getClass();
Class<?> subClazz = arrayClazz.getComponentType();
if (subClazz == null) {
Expand Down Expand Up @@ -1168,7 +1167,7 @@ void appendArray(StringBuilder sb, char delim, Object[] array) {
* Wraps an {@link AbstractArrayEncoder} implementation and provides optimized
* support for 2 dimensions.
*/
private static final class TwoDimensionPrimitiveArrayEncoder<A extends @NonNull Object> implements ArrayEncoder<A @NonNull []> {
private static final class TwoDimensionPrimitiveArrayEncoder<A extends Object> implements ArrayEncoder<A[]> {
private final AbstractArrayEncoder<A> support;

/**
Expand All @@ -1192,7 +1191,7 @@ public int getDefaultArrayTypeOid() {
* {@inheritDoc}
*/
@Override
public String toArrayString(char delim, A @NonNull[] array) {
public String toArrayString(char delim, A[] array) {
final StringBuilder sb = new StringBuilder(1024);
sb.append('{');
for (int i = 0; i < array.length; ++i) {
Expand Down
9 changes: 1 addition & 8 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.postgresql.core.ConnectionFactory;
import org.postgresql.core.Encoding;
import org.postgresql.core.Oid;
import org.postgresql.core.Provider;
import org.postgresql.core.Query;
import org.postgresql.core.QueryExecutor;
import org.postgresql.core.ReplicationProtocol;
Expand Down Expand Up @@ -77,7 +76,6 @@
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -282,12 +280,7 @@ public PgConnection(HostSpec[] hostSpecs,

// Initialize timestamp stuff
timestampUtils = new TimestampUtils(!queryExecutor.getIntegerDateTimes(),
new Provider<@Nullable TimeZone>() {
@Override
public @Nullable TimeZone get() {
return queryExecutor.getTimeZone();
}
});
new QueryExecutorTimeZoneProvider(queryExecutor));

// Initialize common queries.
// isParameterized==true so full parse is performed and the engine knows the query
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/

package org.postgresql.jdbc;

import org.postgresql.core.Provider;
import org.postgresql.core.QueryExecutor;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.TimeZone;

/**
* This class workarounds <a href="https://github.com/wildfly/jandex/issues/93">Exception when
* indexing guava-30.0-jre</a>.
* <p>It looks like {@code jandex} does not support {@code new Interface<..>} with type annotations.
* </p>
*/
class QueryExecutorTimeZoneProvider implements Provider<@Nullable TimeZone> {
private final QueryExecutor queryExecutor;

QueryExecutorTimeZoneProvider(QueryExecutor queryExecutor) {
this.queryExecutor = queryExecutor;
}

@Override
public @Nullable TimeZone get() {
return queryExecutor.getTimeZone();
}
}
3 changes: 1 addition & 2 deletions pgjdbc/src/main/java/org/postgresql/util/LruCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.postgresql.util;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.sql.SQLException;
Expand All @@ -16,7 +15,7 @@
/**
* Caches values in simple least-recently-accessed order.
*/
public class LruCache<Key extends @NonNull Object, Value extends @NonNull CanEstimateSize>
public class LruCache<Key extends Object, Value extends CanEstimateSize>
implements Gettable<Key, Value> {
/**
* Action that is invoked when the entry is removed from the cache.
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pluginManagement {
idv("com.github.vlsi.gettext", "com.github.vlsi.vlsi-release-plugins")
idv("com.github.vlsi.gradle-extensions", "com.github.vlsi.vlsi-release-plugins")
idv("com.github.vlsi.ide", "com.github.vlsi.vlsi-release-plugins")
idv("com.github.vlsi.jandex", "com.github.vlsi.vlsi-release-plugins")
idv("com.github.vlsi.license-gather", "com.github.vlsi.vlsi-release-plugins")
idv("com.github.vlsi.stage-vote-release", "com.github.vlsi.vlsi-release-plugins")
idv("de.thetaphi.forbiddenapis")
Expand Down

0 comments on commit 2df6c97

Please sign in to comment.