dimanche 5 août 2018

java - How to properly circumvent Illegal access exception in this case

so, I'm having this weird issue where even though (I think) I'm setting everything to be accessible correctly, I'm still getting IllegalAccessException.

java.lang.IllegalAccessException: class com.sasha.eventsys.SimpleEventManager can not access a member of class com.sasha.proxy.discord.DiscordMain with modifiers "private"

public void invokeEvent(SimpleEvent e){
    registeredMethods.forEach(method -> {
        if (method.getParameterTypes()[0] == e.getClass()){
            try {
                Class clasz = method.getDeclaringClass();
                for (Field field : clasz.getFields()) {
                    field.setAccessible(true);
                }
                for (Method meth : clasz.getMethods()) {
                    meth.setAccessible(true);
                }
                for (Constructor<?> constructor : clasz.getConstructors()) {
                    constructor.setAccessible(true);
                }
                method.setAccessible(true);
                method.invoke(clasz.newInstance(), e);
            }
            catch (Exception ex){
                System.out.println("FATAL EXCEPTION DURING " + e.getClass().getName() + "'s EXECUTION");
                ex.printStackTrace();
            }
        }
    });
}

This is the code that's invoking the method. In theory those for loops should be setting everything to be accessible, r-right?

@SimpleEventHandler
public void onMcMsgRecieved(MinecraftMessageRecievedEvent e){
    if(Config.doDiscord) {
        DiscordMain.theChannel = DiscordMain.findTheServer(jda.getTextChannelsByName(Config.channelName,false));
        if (Config.aestheticDiscord) {
            DiscordMain.renderViewport(e.getPlainText(), DiscordMain.theChannel, Caches.messagesRecieved==0);
            Caches.messagesRecieved++;
        }
        else {
            DiscordMain.theChannel.sendMessage("```html\n" + e.getPlainText().replace("discord.gg", "zozzle.gg").replace("`", "'").replaceAll("\247[^z]", "") + "\n```").submit();
        }
        Webhooks.pushToHook("```html\n" + e.getPlainText().replace("discord.gg", "zozzle.gg").replace("`", "'").replaceAll("\247[^z]", "") + "\n```");
    }
}

Annd here's where it's supposedly not able to access something. For reference all of the fields and methods called in this block are public or public static, so like, I don't get why it's having problems.





Aucun commentaire:

Enregistrer un commentaire