-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for #667 Illegal Access for JDK 9 or greater
- Loading branch information
Showing
3 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...rs/src/test/java/com/github/jknack/handlebars/context/SetAccessibleValueResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.github.jknack.handlebars.context; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Collections; | ||
|
||
import org.junit.Test; | ||
|
||
public class SetAccessibleValueResolverTest { | ||
|
||
/* | ||
* The following tests require JDK 9 or greater. | ||
* To keep the tests from failing we use junit assume. | ||
*/ | ||
|
||
@Test | ||
public void testSetAccessibleOnJDK9OrGreater() throws Exception { | ||
assumeTrue(getJavaVersion() >= 9); | ||
MethodValueResolver mv = new MethodValueResolver() { | ||
|
||
@Override | ||
protected boolean isUseSetAccessible(Method m) { | ||
return true; | ||
} | ||
}; | ||
try { | ||
mv.resolve(Collections.emptyMap(), "doesNotMatter"); | ||
fail("Expect InaccessibleObjectException"); | ||
} catch (/* InaccessibleObjectException */ Exception e) { | ||
} | ||
|
||
mv = new MethodValueResolver(); | ||
mv.resolve(Collections.emptyMap(), "doesNotMatter"); | ||
Object result = mv.resolve(Collections.emptyMap(), "isEmpty"); | ||
assertEquals(Boolean.TRUE, result); | ||
} | ||
|
||
static int getJavaVersion() { | ||
String version = System.getProperty("java.version"); | ||
if (version.startsWith("1.")) { | ||
version = version.substring(2, 3); | ||
} else { | ||
int dot = version.indexOf("."); | ||
if (dot != -1) { | ||
version = version.substring(0, dot); | ||
} | ||
} | ||
try { | ||
return Integer.parseInt(version); | ||
} catch (NumberFormatException e) { | ||
return 8; | ||
} | ||
} | ||
|
||
} |