rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.77k stars 1.22k forks source link

Error at Example File: An illegal reflective access #637

Closed sf202020sf closed 5 years ago

sf202020sf commented 5 years ago

I followed the instruction on: https://github.com/rubenlagus/TelegramBotsExample/blob/master/HOWTO.md

but when i execute the file I get the following error:

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/C:/Users/sfladi/.m2/repository/com/google/inject/guice/4.2.2/guice-4.2.2.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1 WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release

Attached you will find my code:

`import java.util.logging.Level; import java.util.logging.Logger;

import org.telegram.telegrambots.meta.TelegramBotsApi; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.bots.TelegramLongPollingBot;

import org.telegram.telegrambots.meta.exceptions.TelegramApiException;

public class Telegrambot extends TelegramLongPollingBot {

private String username = "";
private String token = "";
private String laststreamdata = "";

@Override
public void onUpdateReceived(Update update) {
    // We check if the update has a message and the message has text
    if (update.hasMessage() && update.getMessage().hasText()) {
        SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
                .setChatId(update.getMessage().getChatId())
                .setText(update.getMessage().getText());
        System.out.println(update.getMessage().getText());

        try {
            execute(message); // Call method to send the message
        } catch (TelegramApiException e) {
            general.log(Level.WARNING, "Error in Bot can not send message: " + message + "Error Code: " + e.toString());
        }
    }
}

@Override
public String getBotUsername() {
    return username;
}

public void setlocalData() {
    this.username = "StrategyMessageLocal_bot";
    this.token = "ABC";

}

public void setMultiServerData() {
    this.username = "StrategyMessages_bot";
    this.token = "ABC";
}

@Override
public String getBotToken() {
    return token;
}

public void sendMessage(String messagetext) {
    SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
    message.setText(messagetext);
    message.setChatId(Long.parseLong("356456308"));

    try {
        execute(message); // Call method to send the message
    } catch (TelegramApiException e) {
        general.log(Level.WARNING, "Error in Bot can not send message: " + messagetext + "Error Code: " + e.toString());
    }

}

public void setLastStreamData(String data) {
    laststreamdata = data;
}

public static void main(String[] args) {
    TelegramBotsApi botsApi = new TelegramBotsApi();

    Telegrambot bottype = new Telegrambot();
    try {
        botsApi.registerBot(bottype);

    } catch (TelegramApiException e) {
        System.out.println("ERRROR" + e.toString()+e.getMessage());
    }//end catch()
}//end main()

}

`

carlopantaleo commented 5 years ago

This is not an error but a warning and it doesn't prevent your bot to run properly.

If you are running your bot on Java 9+, there is nothing you can do to prevent this warning, as it is generated by a dependency (Guice) and not by this library itself.

More info on this warning: http://openjdk.java.net/jeps/261#Relaxed-strong-encapsulation

sf202020sf commented 5 years ago

ok thx!

shtomik commented 4 years ago

https://github.com/google/guice/issues/1133#issuecomment-596860413