Why is my Java "if" statement only being triggered if I have a watch on it in Netbeans? -


i doing work ties in apache batik ( don't think relevant never know ) , running weird behaviour can't figure out reason for.

the following bit of code calculating height of line of text, can start next line in correct position:

protected double painttextrun(textrun textrun, double x, double y, int linecount, emfgraphics2d g2d) throws ioexception  {      attributedcharacteriterator runaci = textrun.getaci();      char c = runaci.first();      textpaintinfo tpi = (textpaintinfo) runaci.getattribute(paint_info);      if ( tpi == null || !tpi.visible )      {          return y;      }      setfont(runaci, g2d);      g2d.setpaint(tpi.fillpaint);      g2d.writestring(gettextfromaci(runaci, x, y);       if (  runaci.getattribute(textattribute.size) != null )      {         y+= (float)runaci.getattribute(textattribute.size);      }      else if ( textrun.getlayout().getbounds2d() != null )      {          double height = textrun.getlayout().getbounds2d().getheight();          if ( height != null )          {             y+=height/linecount;          }     }     return y;     } 

the thing confusing me when place breakpoint on y+= (float)runaci.getattribute(textattribute.size); line, never triggered, condition falls through else side of statement. , yet if watch value of runaci.getattribute(textattribute.size) in netbeans never appears null. in fact placing watch on exact statement if condition consistently evaluates true when code falling through else. it's quirky.

however if place breakpoint on if ( runaci.getattribute(textattribute.size) != null ) line, evaluates true , go first half of if...else block. take out breakpoint , goes else side.

is kind of quirky bit of jvm optimisation or there kind of evaluation bypass bug limited recent java experience has left me unprepared for?

edit add: comments suggested problem running ide/debugger, on new day after restarting computer , cleaning/rebuilding everything, same problem manifests.

i don't have why of it, if assign result of runaci.getattribute(textattribute.size) call variable, behaves 1 might expect.

  object textsize = runaci.getattribute(textattribute.size);   if (  textsize != null )      {         y+= (float)textsize;      }      else if ( textrun.getlayout().getbounds2d() != null )      {          double height = textrun.getlayout().getbounds2d().getheight();          if ( height != null )          {             y+=height/linecount;          }     } 

probably policy work way in case- possibly side effect of optimisation aimed @ preventing repeat calls same method requiring repeat evaluation.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -