Skip to content

Commit 922e24a

Browse files
committed
java: remove multiple checks for JVM version
- make sure minimum is now Java 17
1 parent 978ec5e commit 922e24a

File tree

7 files changed

+9
-208
lines changed

7 files changed

+9
-208
lines changed

handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,6 @@ public boolean equals(final Object obj) {
157157
*/
158158
public static class Utils {
159159

160-
/** Java 14. */
161-
private static final int JAVA_14 = 14;
162-
163-
/** Current Java version: 8, 11, 15, etc. */
164-
public static final int javaVersion = javaVersion();
165-
166-
/** True when running on Java 14 or higher. */
167-
public static final boolean javaVersion14 = javaVersion() >= JAVA_14;
168-
169-
/** Prefix for Java version: 1.8 (mostly). */
170-
private static final String VERSION_PREFIX = "1.";
171-
172160
/**
173161
* Evaluate the given object and return true is the object is considered empty. Nulls, empty
174162
* list or array and false values are considered empty.
@@ -221,11 +209,6 @@ public static CharSequence escapeExpression(final CharSequence input) {
221209
return EscapingStrategy.DEF.escape(input);
222210
}
223211

224-
static int javaVersion() {
225-
String version = System.getProperty("java.specification.version").trim();
226-
return Integer.parseInt(version.replace(VERSION_PREFIX, ""));
227-
}
228-
229212
/**
230213
* Throws any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it
231214
* onwards. The exception is still thrown - javac will just stop whining about it.

handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
*/
66
package com.github.jknack.handlebars;
77

8-
import static java.util.Arrays.asList;
9-
import static java.util.Collections.unmodifiableList;
10-
118
import java.util.List;
129
import java.util.Map.Entry;
1310
import java.util.Set;
@@ -66,13 +63,7 @@ public interface ValueResolver {
6663
* @return Immutable list of value resolvers.
6764
*/
6865
static List<ValueResolver> defaultValueResolvers() {
69-
if (Handlebars.Utils.javaVersion14) {
70-
return unmodifiableList(
71-
asList(
72-
MapValueResolver.INSTANCE,
73-
JavaBeanValueResolver.INSTANCE,
74-
MethodValueResolver.INSTANCE));
75-
}
76-
return unmodifiableList(asList(MapValueResolver.INSTANCE, JavaBeanValueResolver.INSTANCE));
66+
return List.of(
67+
MapValueResolver.INSTANCE, JavaBeanValueResolver.INSTANCE, MethodValueResolver.INSTANCE);
7768
}
7869
}

handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.io.Writer;
1515
import java.lang.invoke.MethodHandles;
1616
import java.lang.invoke.MethodType;
17-
import java.lang.reflect.Constructor;
1817
import java.lang.reflect.InvocationHandler;
1918
import java.lang.reflect.Method;
2019
import java.lang.reflect.Modifier;
@@ -241,31 +240,12 @@ private Object invokeDefaultMethod(
241240
final Object proxy,
242241
final Object... args)
243242
throws Throwable {
244-
if (Handlebars.Utils.javaVersion14) {
245-
MethodType methodType =
246-
MethodType.methodType(method.getReturnType(), method.getParameterTypes());
247-
return MethodHandles.lookup()
248-
.findSpecial(lookupClass, method.getName(), methodType, lookupClass)
249-
.bindTo(proxy)
250-
.invokeWithArguments(args);
251-
} else {
252-
// Jumping through these hoops is needed because calling unreflectSpecial
253-
// requires
254-
// that the lookup instance have private access to the special caller. None of
255-
// the
256-
// static factory methods for Lookup will give us an instance with the access
257-
// modes
258-
// we need, so we work around it by calling the private constructor via
259-
// reflection.
260-
Constructor<MethodHandles.Lookup> constructor =
261-
MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class);
262-
constructor.setAccessible(true);
263-
return constructor
264-
.newInstance(lookupClass, -1 /* trusted */)
265-
.unreflectSpecial(method, lookupClass)
266-
.bindTo(proxy)
267-
.invokeWithArguments(args);
268-
}
243+
MethodType methodType =
244+
MethodType.methodType(method.getReturnType(), method.getParameterTypes());
245+
return MethodHandles.lookup()
246+
.findSpecial(lookupClass, method.getName(), methodType, lookupClass)
247+
.bindTo(proxy)
248+
.invokeWithArguments(args);
269249
}
270250

271251
@Override

handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.io.IOException;
1111
import java.util.LinkedHashMap;
1212
import java.util.Map.Entry;
13-
import java.util.function.Predicate;
1413

1514
import org.yaml.snakeyaml.Yaml;
1615

@@ -188,10 +187,4 @@ protected Handlebars newHandlebars() {
188187
}
189188
return model;
190189
}
191-
192-
public void withJava(Predicate<Integer> predicate, Task task) throws IOException {
193-
if (predicate.test(Handlebars.Utils.javaVersion)) {
194-
task.run();
195-
}
196-
}
197190
}

handlebars/src/test/java/com/github/jknack/handlebars/JavaVersionTest.java

Lines changed: 0 additions & 74 deletions
This file was deleted.

handlebars/src/test/java/com/github/jknack/handlebars/context/SetAccessibleValueResolverTest.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

tests/src/test/java/com/github/jknack/handlebars/helper/ext/JodaHelperTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ public void testBadPattern() throws IOException {
5656
@Test
5757
public void testStyle() throws IOException {
5858
DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0);
59-
withJava(
60-
version -> version <= 8,
61-
() -> shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95 2:32 PM"));
62-
withJava(
63-
version -> version >= 9,
64-
() -> shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95, 2:32 PM"));
59+
shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95, 2:32 PM");
6560
}
6661

6762
@Test

0 commit comments

Comments
 (0)