Skip to content

Commit a8e2c41

Browse files
authored
feat: support JDK 17 (#247)
1 parent 060e0ed commit a8e2c41

File tree

10 files changed

+242
-12
lines changed

10 files changed

+242
-12
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
33

44
name: Build and Test
55

@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
java-version: [ 8, 11 ]
13+
java-version: [ 8, 11, 17 ]
1414
steps:
1515
- uses: actions/checkout@v3
1616
- name: "Set up JDK ${{ matrix.java-version }}"
@@ -32,10 +32,10 @@ jobs:
3232
- uses: actions/checkout@v3
3333
with:
3434
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
35-
- name: "Set up JDK 11"
35+
- name: "Set up JDK 17"
3636
uses: actions/setup-java@v3
3737
with:
38-
java-version: 11
38+
java-version: 17
3939
distribution: 'temurin'
4040
cache: maven
4141
- name: Cache SonarCloud packages
@@ -55,5 +55,5 @@ jobs:
5555
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
5656
run: mvn --batch-mode --no-transfer-progress --fail-fast clean test verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=arextest_arex-agent-java -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=arextest -Dsonar.token=1f4a261beca6bbf7c93c3cf80bbc198de74d1020 -DskipTests=false
5757
- name: Codecov
58-
uses: codecov/codecov-action@v3.1.0
58+
uses: codecov/codecov-action@v3
5959

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
package io.arex.agent.bootstrap.model;
2+
3+
import java.lang.reflect.MalformedParameterizedTypeException;
4+
import java.lang.reflect.ParameterizedType;
5+
import java.lang.reflect.Type;
6+
import java.lang.reflect.TypeVariable;
7+
import java.util.Arrays;
8+
import java.util.Objects;
9+
10+
/**
11+
* ref: <a
12+
* href="https://github.com/openjdk/jdk17/blob/master/src/java.base/share/classes/sun/reflect/generics/reflectiveObjects/ParameterizedTypeImpl.java">
13+
* sun/reflect/generics/reflectiveObjects/ParameterizedTypeImpl.java
14+
* </a>
15+
*/
16+
public class ParameterizedTypeImpl implements ParameterizedType {
17+
private final Type[] actualTypeArguments;
18+
private final Class<?> rawType;
19+
private final Type ownerType;
20+
21+
private ParameterizedTypeImpl(Class<?> rawType,
22+
Type[] actualTypeArguments,
23+
Type ownerType) {
24+
this.actualTypeArguments = actualTypeArguments;
25+
this.rawType = rawType;
26+
this.ownerType = (ownerType != null) ? ownerType : rawType.getDeclaringClass();
27+
validateConstructorArguments();
28+
}
29+
30+
private void validateConstructorArguments() {
31+
TypeVariable<?>[] formals = rawType.getTypeParameters();
32+
// check correct arity of actual type args
33+
if (formals.length != actualTypeArguments.length){
34+
throw new MalformedParameterizedTypeException();
35+
}
36+
for (int i = 0; i < actualTypeArguments.length; i++) {
37+
// check actuals against formals' bounds
38+
}
39+
}
40+
41+
/**
42+
* Static factory. Given a (generic) class, actual type arguments
43+
* and an owner type, creates a parameterized type.
44+
* This class can be instantiated with a a raw type that does not
45+
* represent a generic type, provided the list of actual type
46+
* arguments is empty.
47+
* If the ownerType argument is null, the declaring class of the
48+
* raw type is used as the owner type.
49+
* <p> This method throws a MalformedParameterizedTypeException
50+
* under the following circumstances:
51+
* If the number of actual type arguments (i.e., the size of the
52+
* array <tt>typeArgs</tt>) does not correspond to the number of
53+
* formal type arguments.
54+
* If any of the actual type arguments is not an instance of the
55+
* bounds on the corresponding formal.
56+
* @param rawType the Class representing the generic type declaration being
57+
* instantiated
58+
* @param actualTypeArguments - a (possibly empty) array of types
59+
* representing the actual type arguments to the parameterized type
60+
* @param ownerType - the enclosing type, if known.
61+
* @return An instance of <tt>ParameterizedType</tt>
62+
* @throws MalformedParameterizedTypeException - if the instantiation
63+
* is invalid
64+
*/
65+
public static ParameterizedTypeImpl make(Class<?> rawType,
66+
Type[] actualTypeArguments,
67+
Type ownerType) {
68+
return new ParameterizedTypeImpl(rawType, actualTypeArguments,
69+
ownerType);
70+
}
71+
72+
73+
/**
74+
* Returns an array of <tt>Type</tt> objects representing the actual type
75+
* arguments to this type.
76+
*
77+
* <p>Note that in some cases, the returned array be empty. This can occur
78+
* if this type represents a non-parameterized type nested within
79+
* a parameterized type.
80+
*
81+
* @return an array of <tt>Type</tt> objects representing the actual type
82+
* arguments to this type
83+
* @throws <tt>TypeNotPresentException</tt> if any of the
84+
* actual type arguments refers to a non-existent type declaration
85+
* @throws <tt>MalformedParameterizedTypeException</tt> if any of the
86+
* actual type parameters refer to a parameterized type that cannot
87+
* be instantiated for any reason
88+
* @since 1.5
89+
*/
90+
public Type[] getActualTypeArguments() {
91+
return actualTypeArguments.clone();
92+
}
93+
94+
/**
95+
* Returns the <tt>Type</tt> object representing the class or interface
96+
* that declared this type.
97+
*
98+
* @return the <tt>Type</tt> object representing the class or interface
99+
* that declared this type
100+
*/
101+
public Class<?> getRawType() {
102+
return rawType;
103+
}
104+
105+
106+
/**
107+
* Returns a <tt>Type</tt> object representing the type that this type
108+
* is a member of. For example, if this type is <tt>O<T>.I<S></tt>,
109+
* return a representation of <tt>O<T></tt>.
110+
*
111+
* <p>If this type is a top-level type, <tt>null</tt> is returned.
112+
*
113+
* @return a <tt>Type</tt> object representing the type that
114+
* this type is a member of. If this type is a top-level type,
115+
* <tt>null</tt> is returned
116+
* @throws <tt>TypeNotPresentException</tt> if the owner type
117+
* refers to a non-existent type declaration
118+
* @throws <tt>MalformedParameterizedTypeException</tt> if the owner type
119+
* refers to a parameterized type that cannot be instantiated
120+
* for any reason
121+
*
122+
*/
123+
public Type getOwnerType() {
124+
return ownerType;
125+
}
126+
127+
/*
128+
* From the JavaDoc for java.lang.reflect.ParameterizedType
129+
* "Instances of classes that implement this interface must
130+
* implement an equals() method that equates any two instances
131+
* that share the same generic type declaration and have equal
132+
* type parameters."
133+
*/
134+
@Override
135+
public boolean equals(Object o) {
136+
if (o instanceof ParameterizedType) {
137+
// Check that information is equivalent
138+
ParameterizedType that = (ParameterizedType) o;
139+
140+
if (this == that)
141+
return true;
142+
143+
Type thatOwner = that.getOwnerType();
144+
Type thatRawType = that.getRawType();
145+
146+
if (false) { // Debugging
147+
boolean ownerEquality = (ownerType == null ?
148+
thatOwner == null :
149+
ownerType.equals(thatOwner));
150+
boolean rawEquality = (rawType == null ?
151+
thatRawType == null :
152+
rawType.equals(thatRawType));
153+
154+
boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone
155+
that.getActualTypeArguments());
156+
for (Type t : actualTypeArguments) {
157+
System.out.printf("\t\t%s%s%n", t, t.getClass());
158+
}
159+
160+
System.out.printf("\towner %s\traw %s\ttypeArg %s%n",
161+
ownerEquality, rawEquality, typeArgEquality);
162+
return ownerEquality && rawEquality && typeArgEquality;
163+
}
164+
165+
return
166+
Objects.equals(ownerType, thatOwner) &&
167+
Objects.equals(rawType, thatRawType) &&
168+
Arrays.equals(actualTypeArguments, // avoid clone
169+
that.getActualTypeArguments());
170+
} else
171+
return false;
172+
}
173+
174+
@Override
175+
public int hashCode() {
176+
return
177+
Arrays.hashCode(actualTypeArguments) ^
178+
Objects.hashCode(ownerType) ^
179+
Objects.hashCode(rawType);
180+
}
181+
182+
public String toString() {
183+
StringBuilder sb = new StringBuilder();
184+
185+
if (ownerType != null) {
186+
if (ownerType instanceof Class)
187+
sb.append(((Class)ownerType).getName());
188+
else
189+
sb.append(ownerType.toString());
190+
191+
sb.append("$");
192+
193+
if (ownerType instanceof ParameterizedTypeImpl) {
194+
// Find simple name of nested type by removing the
195+
// shared prefix with owner.
196+
sb.append(rawType.getName().replace( ((ParameterizedTypeImpl)ownerType).rawType.getName() + "$",
197+
""));
198+
} else
199+
sb.append(rawType.getSimpleName());
200+
} else
201+
sb.append(rawType.getName());
202+
203+
if (actualTypeArguments != null &&
204+
actualTypeArguments.length > 0) {
205+
sb.append("<");
206+
boolean first = true;
207+
for(Type t: actualTypeArguments) {
208+
if (!first)
209+
sb.append(", ");
210+
sb.append(t.getTypeName());
211+
first = false;
212+
}
213+
sb.append(">");
214+
}
215+
216+
return sb.toString();
217+
}
218+
}

arex-attacher/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<plugin>
2828
<groupId>org.apache.maven.plugins</groupId>
2929
<artifactId>maven-jar-plugin</artifactId>
30+
<version>${maven-jar-plugin.version}</version>
3031
<executions>
3132
<execution>
3233
<phase>package</phase>

arex-instrumentation-api/src/main/java/io/arex/inst/runtime/util/TypeUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.arex.inst.runtime.util;
22

3+
import io.arex.agent.bootstrap.model.ParameterizedTypeImpl;
34
import io.arex.agent.bootstrap.util.ArrayUtils;
45
import io.arex.agent.bootstrap.util.StringUtil;
56
import io.arex.inst.runtime.log.LogManager;
@@ -15,7 +16,6 @@
1516
import java.util.List;
1617
import java.util.concurrent.ConcurrentHashMap;
1718
import java.util.concurrent.ConcurrentMap;
18-
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
1919

2020
public class TypeUtil {
2121

arex-instrumentation-api/src/test/java/io/arex/inst/runtime/util/TypeUtilTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.arex.inst.runtime.util;
22

33
import io.arex.agent.bootstrap.internal.Pair;
4+
import io.arex.agent.bootstrap.model.ParameterizedTypeImpl;
45
import io.arex.agent.bootstrap.util.CollectionUtil;
56
import io.arex.agent.bootstrap.util.StringUtil;
67
import java.lang.reflect.Field;
@@ -22,7 +23,6 @@
2223
import org.junit.jupiter.params.provider.MethodSource;
2324
import org.mockito.MockedStatic;
2425
import org.mockito.Mockito;
25-
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
2626

2727
import static org.junit.jupiter.api.Assertions.*;
2828
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -251,4 +251,4 @@ void testSerializeObjectToString() {
251251
final String arg2Type = TypeUtil.errorSerializeToString(arg2);
252252
assertEquals("java.lang.Double", arg2Type);
253253
}
254-
}
254+
}

arex-instrumentation-foundation/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>com.google.code.gson</groupId>
4646
<artifactId>gson</artifactId>
47-
<version>2.8.9</version>
47+
<version>2.10.1</version>
4848
</dependency>
4949
<dependency>
5050
<groupId>com.google.guava</groupId>

arex-instrumentation/dynamic/arex-cache/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<dependency>
2929
<groupId>com.arextest</groupId>
3030
<artifactId>arex-common</artifactId>
31-
<version>0.1.4</version>
31+
<version>${arex-common.version}</version>
3232
<scope>provided</scope>
3333
</dependency>
3434
</dependencies>

arex-instrumentation/dynamic/arex-dynamic/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>com.arextest</groupId>
2424
<artifactId>arex-common</artifactId>
25-
<version>0.1.4</version>
25+
<version>${arex-common.version}</version>
2626
<scope>provided</scope>
2727
</dependency>
2828
</dependencies>

arex-instrumentation/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<properties>
1616
<springframework.version>5.3.24</springframework.version>
17+
<arex-common.version>0.1.6</arex-common.version>
1718
</properties>
1819

1920
<modules>

pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,17 @@
223223
<plugin>
224224
<groupId>org.apache.maven.plugins</groupId>
225225
<artifactId>maven-surefire-plugin</artifactId>
226-
<version>2.22.2</version>
226+
<version>3.1.2</version>
227+
<configuration>
228+
<argLine>
229+
--add-opens java.base/java.lang=ALL-UNNAMED
230+
--add-opens java.base/java.math=ALL-UNNAMED
231+
--add-opens java.base/java.util=ALL-UNNAMED
232+
--add-opens java.base/java.net=ALL-UNNAMED
233+
--add-opens java.base/java.time=ALL-UNNAMED
234+
--add-opens java.xml/com.sun.org.apache.xerces.internal.jaxp.datatype=ALL-UNNAMED
235+
</argLine>
236+
</configuration>
227237
</plugin>
228238
<plugin>
229239
<groupId>org.jacoco</groupId>

0 commit comments

Comments
 (0)