Skip to content

Commit

Permalink
Merge pull request #308 from Ladicek/type-var-ref-reproducibility
Browse files Browse the repository at this point in the history
make type variable reference serialization reproducible
  • Loading branch information
Ladicek authored Apr 13, 2023
2 parents cdfb090 + 2f755e7 commit 5c651d7
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ public int hashCode() {
return hash;
}

// unlike all other subclasses of `Type`, this class is mutable,
// so identity equality and hash code are the only option
// unlike all other subclasses of `Type`, this class is mutable, so identity is the only option
@Override
boolean internEquals(Object o) {
return this == o;
}

@Override
int internHashCode() {
return System.identityHashCode(this);
// must produce predictable hash code (for reproducibility) consistent with `internEquals`
return name.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

import org.junit.jupiter.api.Test;

Expand All @@ -30,11 +29,9 @@ public void verifyJava8() throws IOException {
}

private void verifyMagic(DataInputStream stream) throws IOException {
byte[] buf = new byte[4];

stream.readFully(buf);
if (buf[0] != (byte) 0xCA || buf[1] != (byte) 0xFE || buf[2] != (byte) 0xBA || buf[3] != (byte) 0xBE) {
fail("Invalid magic value: " + Arrays.toString(buf));
int magic = stream.readInt();
if (magic != 0xCA_FE_BA_BE) {
fail("Invalid magic value: " + Integer.toHexString(magic));
}
}

Expand Down
2 changes: 1 addition & 1 deletion maven-plugin/src/it/reproducible/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

invoker.goals = clean test

invoker.goals.2 = test -DindexName=jandex-2.idx
invoker.goals.2 = clean test -DindexName=jandex-2.idx
4 changes: 3 additions & 1 deletion maven-plugin/src/it/reproducible/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
<goal>jandex</goal>
</goals>
<configuration>
<!-- so that the 2nd execution of `mvn clean test` doesn't delete the previous index file -->
<indexDir>${project.basedir}</indexDir>
<indexName>${indexName}</indexName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;

public class BasicAnnotation {
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -134,4 +136,21 @@ public void f() {
ApiClass.superApi();
}
}

public static class GenericClass<T extends Number> {
public T get(Map<? super Integer, Map<? extends Number, ?>> wildcards) {
return null;
}

public <X extends T> void set(List<X> x) {
}
}

public abstract static class TypeVarRefUsage<B extends TypeVarRefUsage<B>> {
public void doSomething() {
}

public void useSelfType(B b) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;

public class BasicAnnotation2 {
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -134,4 +136,21 @@ public void f() {
ApiClass.superApi();
}
}

public static class GenericClass<T extends Number> {
public T get(Map<? super Integer, Map<? extends Number, ?>> wildcards) {
return null;
}

public <X extends T> void set(List<X> x) {
}
}

public abstract static class TypeVarRefUsage<B extends TypeVarRefUsage<B>> {
public void doSomething() {
}

public void useSelfType(B b) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;

public class SubAnnotation {
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -134,4 +136,21 @@ public void f() {
ApiClass.superApi();
}
}

public static class GenericClass<T extends Number> {
public T get(Map<? super Integer, Map<? extends Number, ?>> wildcards) {
return null;
}

public <X extends T> void set(List<X> x) {
}
}

public abstract static class TypeVarRefUsage<B extends TypeVarRefUsage<B>> {
public void doSomething() {
}

public void useSelfType(B b) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;

public class SubAnnotation2 {
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -134,4 +136,21 @@ public void f() {
ApiClass.superApi();
}
}

public static class GenericClass<T extends Number> {
public T get(Map<? super Integer, Map<? extends Number, ?>> wildcards) {
return null;
}

public <X extends T> void set(List<X> x) {
}
}

public abstract static class TypeVarRefUsage<B extends TypeVarRefUsage<B>> {
public void doSomething() {
}

public void useSelfType(B b) {
}
}
}
6 changes: 3 additions & 3 deletions maven-plugin/src/it/reproducible/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def jandexFile = new File(basedir, 'target/classes/META-INF/jandex.idx')
def jandexFile2 = new File(basedir, 'target/classes/META-INF/jandex-2.idx')
def jandexFile = new File(basedir, 'jandex.idx')
def jandexFile2 = new File(basedir, 'jandex-2.idx')

assert jandexFile.exists() : "File does not exist: ${jandexFile}"
assert jandexFile2.exists() : "File does not exist: ${jandexFile}"
assert jandexFile2.exists() : "File does not exist: ${jandexFile2}"

byte[] idx = jandexFile.bytes
byte[] idx2 = jandexFile2.bytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

import org.junit.jupiter.api.Test;

Expand All @@ -30,11 +29,9 @@ public void verifyJava8() throws IOException {
}

private void verifyMagic(DataInputStream stream) throws IOException {
byte[] buf = new byte[4];

stream.readFully(buf);
if (buf[0] != (byte) 0xCA || buf[1] != (byte) 0xFE || buf[2] != (byte) 0xBA || buf[3] != (byte) 0xBE) {
fail("Invalid magic value: " + Arrays.toString(buf));
int magic = stream.readInt();
if (magic != 0xCA_FE_BA_BE) {
fail("Invalid magic value: " + Integer.toHexString(magic));
}
}

Expand Down

0 comments on commit 5c651d7

Please sign in to comment.