Skip to content

Commit

Permalink
HSEARCH-4556 Upgrade to JDK 11
Browse files Browse the repository at this point in the history
- set main java version
- remove jdk 8 profiles
- remove/replace some removed/deprecated code
  • Loading branch information
marko-bekhta committed Jun 5, 2023
1 parent 78c77ae commit 292ee60
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 104 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ and then you will need to pass additional properties to Maven.
To test Hibernate Search against JDK 8:

```bash
./mvnw clean install -Djava-version.test.release=8 -Djava-version.test.launcher.java_home=/path/to/jdk8
./mvnw clean install -Djava-version.test.release=11 -Djava-version.test.launcher.java_home=/path/to/jdk11
```

To test Hibernate Search against JDKs other than 8 or the default 17:
To test Hibernate Search against JDKs other than 11 or the default 17:

```bash
./mvnw clean install -Djava-version.test.release=11 -Djava-version.test.compiler.java_home=/path/to/jdk11
./mvnw clean install -Djava-version.test.release=15 -Djava-version.test.compiler.java_home=/path/to/jdk15
```

Or more simply, if the newer JDK you want to test against is newer than 17 and is your default JDK:
Expand Down
3 changes: 0 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ stage('Configure') {
jdk: [
// This should not include every JDK; in particular let's not care too much about EOL'd JDKs like version 9
// See http://www.oracle.com/technetwork/java/javase/eol-135779.html
// We only run the tests with JDK8, but we compile them with JDK17 (with --release 8).
new JdkBuildEnvironment(version: '8', testLauncherTool: 'OpenJDK 8 Latest',
condition: TestCondition.AFTER_MERGE),
new JdkBuildEnvironment(version: '11', testCompilerTool: 'OpenJDK 11 Latest',
condition: TestCondition.AFTER_MERGE),
new JdkBuildEnvironment(version: '17', testCompilerTool: 'OpenJDK 17 Latest',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.concurrent.ThreadFactory;

import org.hibernate.search.engine.environment.thread.spi.ThreadProvider;
import org.hibernate.search.util.common.annotation.impl.SuppressForbiddenApis;

public final class EmbeddedThreadProvider implements ThreadProvider {

Expand All @@ -31,11 +30,8 @@ public String createThreadName(String prefix, int threadNumber) {
}

@Override
@SuppressForbiddenApis(reason = "It's unclear how we will handle this without the security manager;"
+ " we'll see when the security manager actually gets removed from the JDK")
public ThreadFactory createThreadFactory(String prefix) {
SecurityManager s = System.getSecurityManager();
ThreadGroup group = ( s != null ) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
ThreadGroup group = Thread.currentThread().getThreadGroup();
String namePrefix = createFullThreadNamePrefix( prefix );
return new SimpleThreadFactory( group, namePrefix );
}
Expand All @@ -44,4 +40,4 @@ private String createFullThreadNamePrefix(String prefix) {
return commonThreadNamePrefix + prefix + " - ";
}

}
}
26 changes: 0 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2562,32 +2562,6 @@
</properties>
</profile>

<profile>
<id>testWithJdk8</id>
<activation>
<property>
<name>java-version.test.release</name>
<value>8</value>
</property>
</activation>
<properties>
<!-- JDK 8 doesn't support the settings mentioned in the default value of this property,
but it doesn't need them either, so we just omit them. -->
<surefire.jvm.args.java-version></surefire.jvm.args.java-version>
<!-- JDK 8 produces so many false positives that warnings are worthless -->
<maven.compiler.failOnWarning>false</maven.compiler.failOnWarning>
<!-- JDK 8 doesn't support the add-opens mentioned in the default value of this property,
but it doesn't need them either, so we just omit them. -->
<test.weld.jvm.args></test.weld.jvm.args>
<!-- Tests specific to Java 11+ won't work with JDK 8, so we disable them. -->
<java-version.test.java11.add-main-source-phase>none</java-version.test.java11.add-main-source-phase>
<java-version.test.java17.add-main-source-phase>none</java-version.test.java17.add-main-source-phase>
<java-version.test.java11.add-test-source-phase>none</java-version.test.java11.add-test-source-phase>
<java-version.test.java17.add-test-source-phase>none</java-version.test.java17.add-test-source-phase>
<java-version.test.java17.noParameters.skip>true</java-version.test.java17.noParameters.skip>
</properties>
</profile>

<profile>
<id>testWithJdk11</id>
<activation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
*/
package org.hibernate.search.util.impl.test.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Optional;
import java.util.function.Function;
Expand All @@ -19,25 +16,7 @@ public final class RuntimeHelper {
private static final CallerClassWalker CALLER_CLASS_WALKER;

static {
Class<?> stackWalkerClass = null;
try {
stackWalkerClass = Class.forName( "java.lang.StackWalker" );
}
catch (ClassNotFoundException ignored) {
}
if ( stackWalkerClass != null ) {
// JDK 9+, where StackWalker is available
try {
CALLER_CLASS_WALKER = new StackWalkerCallerClassWalker( stackWalkerClass );
}
catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | RuntimeException e) {
throw new IllegalStateException( "Unable to initialize ClassWalker based on java.lang.StackWaker", e );
}
}
else {
// JDK 8
CALLER_CLASS_WALKER = new SecurityManagerCallerClassWalker();
}
CALLER_CLASS_WALKER = new StackWalkerCallerClassWalker();
}

private RuntimeHelper() {
Expand Down Expand Up @@ -100,62 +79,26 @@ public interface CallerClassWalker {
<T> T walk(Function<? super Stream<Class<?>>, ? extends T> function);
}

/**
* Retrieves the caller stack from the security manager class context.
*/
@SuppressWarnings("removal")
private static class SecurityManagerCallerClassWalker extends SecurityManager
implements CallerClassWalker {
@Override
public <T> T walk(Function<? super Stream<Class<?>>, ? extends T> function) {
// The type arguments *are* necessary for some reason.
// Without them, we get strange compilation errors when targeting JDK 8.
return function.apply( Arrays.<Class<?>>stream( getClassContext() )
.skip( 1 ) // Skip this method
.filter( c -> !c.isSynthetic() ) // Skip lambdas, like StackWalker does
);
}
}

/**
* Retrieves the caller stack using a StackWalker.
*/
private static class StackWalkerCallerClassWalker
implements CallerClassWalker {
private final Object stackWalker;
private final Method stackWalkerWalkMethod;
private final Function<Object, Class<?>> stackFrameGetDeclaringClassFunction;

private StackWalkerCallerClassWalker(Class<?> stackWalkerClass)
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<?> optionClass = Class.forName( "java.lang.StackWalker$Option" );
this.stackWalker = stackWalkerClass.getMethod( "getInstance", optionClass )
.invoke( null, optionClass.getEnumConstants()[0] );
private static class StackWalkerCallerClassWalker implements CallerClassWalker {
private final StackWalker stackWalker;

this.stackWalkerWalkMethod = stackWalkerClass.getMethod( "walk", Function.class );
Method stackFrameGetDeclaringClass = Class.forName( "java.lang.StackWalker$StackFrame" )
.getMethod( "getDeclaringClass" );
stackFrameGetDeclaringClassFunction = frame -> {
try {
return (Class<?>) stackFrameGetDeclaringClass.invoke( frame );
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new IllegalStateException( "Unable to get stack frame declaring class", e );
}
};
private StackWalkerCallerClassWalker() {
this.stackWalker = StackWalker.getInstance( StackWalker.Option.RETAIN_CLASS_REFERENCE );
}

@Override
@SuppressWarnings("unchecked")
public <T> T walk(Function<? super Stream<Class<?>>, ? extends T> function) {
Function<Stream<?>, T> stackFrameExtractFunction =
Function<Stream<StackWalker.StackFrame>, T> stackFrameExtractFunction =
stream -> function.apply( stream
.skip( 1 ) // Skip this method
.map( stackFrameGetDeclaringClassFunction ) );
.map( StackWalker.StackFrame::getDeclaringClass ) );
try {
return (T) stackWalkerWalkMethod.invoke( stackWalker, stackFrameExtractFunction );
return stackWalker.walk( stackFrameExtractFunction );
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
catch (IllegalArgumentException e) {
throw new IllegalStateException( "Unable to walk the stack using StackWalker", e );
}
}
Expand Down

0 comments on commit 292ee60

Please sign in to comment.