Skip to content

Commit 3c1f1c1

Browse files
imjalpreettdcmeehan
authored andcommitted
Upgrade to Java 17
To enable integration of PrestoFileSystemCache with Hadoop's FileSystem, this commit also modifies the shaded Hadoop version to expose a `setCache` method and removes the `final` modifier from the static CACHE field. This avoids runtime reflection hacks that are incompatible with JDK 17+ and ensures consistent behavior across environments
1 parent 98ab9c6 commit 3c1f1c1

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

pom.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.facebook.airlift</groupId>
77
<artifactId>airbase</artifactId>
8-
<version>98</version>
8+
<version>105</version>
99
</parent>
1010

1111
<groupId>com.facebook.presto.hadoop</groupId>
@@ -462,7 +462,6 @@
462462
<plugin>
463463
<groupId>org.apache.maven.plugins</groupId>
464464
<artifactId>maven-compiler-plugin</artifactId>
465-
<version>3.1</version>
466465
<configuration>
467466
<source>${project.build.targetJdk}</source>
468467
<target>${project.build.targetJdk}</target>
@@ -472,13 +471,11 @@
472471
<plugin>
473472
<groupId>org.apache.maven.plugins</groupId>
474473
<artifactId>maven-surefire-plugin</artifactId>
475-
<version>2.12.4</version>
476474
</plugin>
477475

478476
<plugin>
479477
<groupId>org.apache.maven.plugins</groupId>
480478
<artifactId>maven-source-plugin</artifactId>
481-
<version>2.2.1</version>
482479
<executions>
483480
<execution>
484481
<id>attach-sources</id>

src/main/java/com/facebook/presto/hadoop/HadoopFileSystemCache.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
import org.apache.hadoop.fs.FileSystem;
1717
import org.apache.hadoop.fs.PrestoFileSystemCache;
1818

19-
import java.lang.reflect.Field;
20-
import java.lang.reflect.Modifier;
21-
2219
public final class HadoopFileSystemCache
2320
{
2421
private static PrestoFileSystemCache cache;
@@ -28,26 +25,9 @@ private HadoopFileSystemCache() {}
2825
public static synchronized void initialize()
2926
{
3027
if (cache == null) {
31-
cache = setFinalStatic(FileSystem.class, "CACHE", new PrestoFileSystemCache());
32-
}
33-
}
34-
35-
private static <T> T setFinalStatic(Class<?> clazz, String name, T value)
36-
{
37-
try {
38-
Field field = clazz.getDeclaredField(name);
39-
field.setAccessible(true);
40-
41-
Field modifiersField = Field.class.getDeclaredField("modifiers");
42-
modifiersField.setAccessible(true);
43-
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
44-
45-
field.set(null, value);
46-
47-
return value;
48-
}
49-
catch (ReflectiveOperationException e) {
50-
throw new AssertionError(e);
28+
PrestoFileSystemCache newCache = new PrestoFileSystemCache();
29+
FileSystem.setCache(newCache);
30+
cache = newCache;
5131
}
5232
}
5333
}

src/main/java/org/apache/hadoop/fs/FileSystem.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ public abstract class FileSystem
211211
* FileSystem cache.
212212
*/
213213

214-
static final Cache CACHE = new Cache(new Configuration());
214+
static Cache CACHE = new Cache(new Configuration());
215+
216+
public static void setCache(Cache newCache) {
217+
CACHE = newCache;
218+
}
215219

216220
/**
217221
* The key this instance is stored under in the cache.

0 commit comments

Comments
 (0)