Solved The Interger was just above INT.MAX_INT <- solved

Discussion in 'Plugin Development' started by Banjer_HD, Jan 6, 2017.

Thread Status:
Not open for further replies.
  1. Offline


    My mind = blown right now O_O.

    I Have made some code to ban a player and tested it, didnt work, added debug lines, and I saw that the config was returning an other int then there is in the file?

        public File databasef = new File(getDataFolder(), "/database.yml");
        public YamlConfiguration database = YamlConfiguration.loadConfiguration(databasef);
        public void onEnable() {
            Bukkit.broadcastMessage("" + database.getInt("ban. MY UUID TO TEST .unbantime"));
      MY UUID:
        unbantime: 100000000000
    [13:13:44 INFO]: Ban time in sec:
    [13:13:44 INFO]: 1215752192
    Every time I change the number of the config "path.unbantime" manualy. It is giving me random numbers... I deleted a few 0's and I got a -number. but if I change the number to something small like 10, it is working???

    Thanks for reading, and I hope someone can help!

    IMPORTANT EDIT: I used "Integer.parseInt(database.getInt("ban. MY UUID TO TEST .unbantime"))" And it worked, but only for small numbers... If there is a higher number, it is giving me this error:

    [13:37:03 ERROR]: Error occurred while enabling PLUGINNAME v0.1 (Is it up to date?)
    java.lang.NumberFormatException: For input string: "100000000000000000000"
            at java.lang.NumberFormatException.forInputString(Unknown Source) ~[?:1.8.0_111]
            at java.lang.Integer.parseInt(Unknown Source) ~[?:1.8.0_111]
            at java.lang.Integer.parseInt(Unknown Source) ~[?:1.8.0_111]
    Last edited: Jan 6, 2017
  2. Offline


    You know that int's can only have a range of
    -2147483648 to 2147483647? And your config value is way above that:
    1*10^11 > 2,147483647*10^9

    Use .getLong instead, it can be up to 9223372036854775807
  3. Offline


    @FisheyLP Thanks A LOT! It is fixed now!! thanks... But can the "system.currentTimeMillis() / 1000" go above Long.MAX_LONG?
  4. Offline


    No, for example the date now: 1483710780000 (still smaller than max long), 1483710780000/1000 = 1483710780 even smaller
  5. Offline

    bwfcwalshy Retired Staff

    @Banjer_HD currentTimeMillis returns a long, it simply cannot go above considering it returns it
  6. Offline


  7. Offline

    I Al Istannen

    And for your "random numbers":
    This is just how overflows are handled. Have a look here :)

    This is due to the encoding as "twos complement".

    127 in binary (greatest byte value):
    0111 1111

    -128 in binary (smallest byte value):
    1000 0000

    Now guess what happens when you add one to 127 ;)
    kameronn likes this.
Thread Status:
Not open for further replies.

Share This Page