@@ -30,17 +30,18 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3030
3131 */
3232
33- // Generated by Snowball (build from 867c4ec70debd4daa7fb4d5a9f7759b47887d0b9 )
33+ // Generated by Snowball (build from 9a22f0d3f44cda36677829328fe2642750114d57 )
3434package opennlp .tools .stemmer .snowball ;
3535
36- import java .lang .reflect .Method ;
36+ import java .lang .invoke .MethodHandle ;
37+ import java .lang .invoke .MethodHandles ;
38+ import java .lang .invoke .MethodType ;
39+ import java .util .Locale ;
3740
41+ /**
42+ * Internal class used by Snowball stemmers
43+ */
3844public class Among {
39- public final char [] s ; /* search string */
40- public final int substring_i ; /* index to longest matching substring */
41- public final int result ; /* result of the lookup */
42- public final Method method ; /* method to use if substring matches */
43-
4445 public Among (String s , int substring_i , int result ) {
4546 this .s = s .toCharArray ();
4647 this .substring_i = substring_i ;
@@ -49,14 +50,30 @@ public Among(String s, int substring_i, int result) {
4950 }
5051
5152 public Among (String s , int substring_i , int result , String methodname ,
52- Class <? extends AbstractSnowballStemmer > programclass ) {
53+ MethodHandles . Lookup methodobject ) {
5354 this .s = s .toCharArray ();
5455 this .substring_i = substring_i ;
5556 this .result = result ;
56- try {
57- this .method = programclass .getDeclaredMethod (methodname );
58- } catch (NoSuchMethodException e ) {
59- throw new RuntimeException (e );
57+ final Class <? extends SnowballProgram > clazz = methodobject .lookupClass ().asSubclass (SnowballProgram .class );
58+ if (methodname .length () > 0 ) {
59+ try {
60+ this .method = methodobject .findVirtual (clazz , methodname , MethodType .methodType (boolean .class ))
61+ .asType (MethodType .methodType (boolean .class , SnowballProgram .class ));
62+ } catch (NoSuchMethodException | IllegalAccessException e ) {
63+ throw new RuntimeException (String .format (Locale .ENGLISH ,
64+ "Snowball program '%s' is broken, cannot access method: boolean %s()" ,
65+ clazz .getSimpleName (), methodname
66+ ), e );
67+ }
68+ } else {
69+ this .method = null ;
6070 }
6171 }
62- }
72+
73+ final char [] s ; /* search string */
74+ final int substring_i ; /* index to longest matching substring */
75+ final int result ; /* result of the lookup */
76+
77+ // Make sure this is not accessible outside package for Java security reasons!
78+ final MethodHandle method ; /* method to use if substring matches */
79+ };
0 commit comments