• Type: Bug
    • Resolution: Fixed
    • Priority: Major
    • None
    • Affects Version/s: None
    • Environment:

      Spigot 1.8.8-R0.1-SNAPSHOT

    • Working on it

      When i get the type of a potion and the type is WATER, Potion.getType() return NULL.

          [SPIGOT-1164] Potion.getType() NPE when the type is WATER

          t. hartmann added a comment - - edited

          hi, i create the ItemStack with:

          player.getItemInHand();
          

          if the potion, that the player hold in hand, is a water potion, then it return null, not PotionType.WATER.
          For now i use the check for null and set the message in code to "Water"

          t. hartmann added a comment - - edited hi, i create the ItemStack with: player.getItemInHand(); if the potion, that the player hold in hand, is a water potion, then it return null, not PotionType.WATER. For now i use the check for null and set the message in code to "Water"

          DemonWav added a comment -

          Potion.fromItemStack() gets the Potion from Potion.fromDamage(). fromDamage() can return a Potion with a null PotionType when the given damage doesn't correspond with a Potion. fromItemStack() uses the item's durability (or damage value) for this. You probably have an itemstack with a weird durability for some reason. The bug here is probably just poor documentation.

          If that's not the issue please show the ItemStacks you are using to create the Potion.

          DemonWav added a comment - Potion.fromItemStack() gets the Potion from Potion.fromDamage(). fromDamage() can return a Potion with a null PotionType when the given damage doesn't correspond with a Potion. fromItemStack() uses the item's durability (or damage value) for this. You probably have an itemstack with a weird durability for some reason. The bug here is probably just poor documentation. If that's not the issue please show the ItemStacks you are using to create the Potion.

          t. hartmann added a comment - - edited

          thats the code snipped:

          	public static List<String> CreateItemStackMessage(ItemStack item,myTrade plugin)
              {
              	String strItem=ChatColor.GOLD.toString() +ChatColor.ITALIC +"Item         : ";
              	
              	String strDurability=ChatColor.GOLD.toString() +ChatColor.ITALIC +"Haltbarkeit : ";
              	String strAnz=ChatColor.GOLD.toString() +ChatColor.ITALIC +"Anzahl      : ";
              	List<String> mess=new ArrayList<String>();
              	//************ NAME ***********
              	Material mat=item.getType();
              	if(mat==Material.POTION)
              	{
              		int data=item.getDurability();
              		if(data==16) mess.add(strItem+"Seltsamer Trank");
              		else if(data==32) mess.add(strItem+"Dickflüssiger Trank");
              		else if(data==64) mess.add(strItem+"Gewöhnlicher Trank (verlängert)");
              		else if(data==8192) mess.add(strItem+"Gewöhnlicher Trank");
              		else
              		{
              			//HIER !!!!
              			Potion po=Potion.fromItemStack(item);
              			String wurf="",level="";
              			if(po.isSplash()) wurf="Wurf";
              			if(po.getLevel()==2) level=" II";
              			else if(po.getLevel()>2) level=String.valueOf(po.getLevel());
              			int dauer=0;
              			for(PotionEffect effect :po.getEffects()) dauer=effect.getDuration()/20;
              			int min=dauer/60;
              			dauer=dauer-min*60;
          //***** HERE ****
              			if(po.getType()==null) plugin.getLogger().warning("***************** NULL");
              			else plugin.getLogger().warning("*****************"+po.getType());
              			mess.add(strItem+wurf+plugin.PotionNames.get(po.getType().toString())+level+" ("+min+":"+dauer+")");
              		}
              	}
          ......
          

          t. hartmann added a comment - - edited thats the code snipped: public static List< String > CreateItemStackMessage(ItemStack item,myTrade plugin) { String strItem=ChatColor.GOLD.toString() +ChatColor.ITALIC + "Item : " ; String strDurability=ChatColor.GOLD.toString() +ChatColor.ITALIC + "Haltbarkeit : " ; String strAnz=ChatColor.GOLD.toString() +ChatColor.ITALIC + "Anzahl : " ; List< String > mess= new ArrayList< String >(); //************ NAME *********** Material mat=item.getType(); if (mat==Material.POTION) { int data=item.getDurability(); if (data==16) mess.add(strItem+ "Seltsamer Trank" ); else if (data==32) mess.add(strItem+ "Dickflüssiger Trank" ); else if (data==64) mess.add(strItem+ "Gewöhnlicher Trank (verlängert)" ); else if (data==8192) mess.add(strItem+ "Gewöhnlicher Trank" ); else { //HIER !!!! Potion po=Potion.fromItemStack(item); String wurf= "",level=" "; if (po.isSplash()) wurf= "Wurf" ; if (po.getLevel()==2) level= " II" ; else if (po.getLevel()>2) level= String .valueOf(po.getLevel()); int dauer=0; for (PotionEffect effect :po.getEffects()) dauer=effect.getDuration()/20; int min=dauer/60; dauer=dauer-min*60; //***** HERE **** if (po.getType()== null ) plugin.getLogger().warning( "***************** NULL" ); else plugin.getLogger().warning( "*****************" +po.getType()); mess.add(strItem+wurf+plugin.PotionNames.get(po.getType().toString())+level+ " (" +min+ ":" +dauer+ ")" ); } } ......

          md_5 added a comment -

          Can you be specific with your code? The following unit test passes:
          assertEquals(PotionType.WATER, potion.getType());

          md_5 added a comment - Can you be specific with your code? The following unit test passes: assertEquals(PotionType.WATER, potion.getType());

          t. hartmann added a comment -

          same with the Spigot version: [18:02:34 INFO]: git-Spigot-0359393-9a17f01 - 1.8.8-R0.1-SNAPSHOT)

          t. hartmann added a comment - same with the Spigot version: [18:02:34 INFO] : git-Spigot-0359393-9a17f01 - 1.8.8-R0.1-SNAPSHOT)

          SpigotMC added a comment -

          Your build is not the latest and therefore may be the reason you are having this issue. Spigot is 1 version(s) behind. CraftBukkit is 1 version(s) behind. This message was automatically generated and is not guaranteed to be a solution to your issue.

          SpigotMC added a comment - Your build is not the latest and therefore may be the reason you are having this issue. Spigot is 1 version(s) behind. CraftBukkit is 1 version(s) behind. This message was automatically generated and is not guaranteed to be a solution to your issue.

            Assignee:
            Unassigned
            Reporter:
            t. hartmann
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: