jeudi 20 décembre 2018

reflection API is throwing no such method exception while migrating to java 9

I am migrating to java 9 from java 8 I was using reflection to fetch method 'getStackTraceElement(int)' from class 'java.lang.Throwable' And I was setting the accessibility to "true".

programs works fine for java 8 but when I migrated to java 9 , It started failing with error 'java.lang.NoSuchMethodException: java.lang.Throwable.getStackTraceElement(int) . '

I have the code which works fine in java 8 as following private static Method m;

'public static void main(String args[])
{
    try 
    {
        System.out.println("here1");
        //next line throws error
        m = Throwable.class.getDeclaredMethod("getStackTraceElement",int.class);
        m.setAccessible(true);
        System.out.println("here2");
    } catch (Exception e) {

        //logger.warn(e.getLocalizedMessage(), e);
        System.out.println("==>"+e.getLocalizedMessage);
        System.out.println("==>"+e.getName);
        System.out.println("==>"+e.getStackTraceElement);
        System.out.println("here3");
    }
}'





Aucun commentaire:

Enregistrer un commentaire