Hi all

Since the latest LTS Java 17 has been released, it's better to support
building ShardingSphere with JDK 17. I've upgraded some plugins to
support Java 17, but there are still some issues.

In some unit tests, we changes the modifiers of Field by reflection
like the following codes, which is not allowed since Java 12. It will
cause `java.lang.NoSuchFieldException: modifiers`.

```
private static void setFinalStatic(final Field field, final Object
newValue) throws NoSuchFieldException, IllegalAccessException {
    field.setAccessible(true);
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
    field.set(null, newValue);
}
```

The temporary solution is ignoring tests which changed Field's
modifiers when using Java 12 or later:
https://github.com/apache/shardingsphere/blob/ebe58d252e428d1d68248d81cb034ccc1e034aa4/shardingsphere-infra/shardingsphere-infra-executor/pom.xml#L64-L85

I have 2 ideas about this issue:
1. Refactoring tests like this: https://stackoverflow.com/a/69418150/7913731
2. Refactoring tests by PowerMock.

I want to ask for advice about this issue.

------------------

Sincerely,
Weijie Wu (TeslaCN)
Apache ShardingSphere

Reply via email to