Yet another Major JIT Optimizer BUG

  • Thread starter Thread starter Guest
  • Start date Start date
Not sure, but the bug is not major, as it requires you use an object without
actually using it to reproduce it. As soon as you place even one statement
in the using block, it magically goes away.

The only way to trigger the bug in an application is to chain behavior to a
constructor, which is an unwise practice.

Sure, it is a bug, but it would be low on my priority list, as well.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***********************************************
Think Outside the Box!
***********************************************
 
NOTE: I am not stating this is not a bug, but trying to illustrate why it
might have been in there and why it is not MAJOR.

1. Exceptions are driven by behavior, not state. At least in a properly
designed system.

2. As constructors set state and do not trigger behavior, at least in a
properly designed system, you should not trigger an exception, so the
compiler apparently "optimizes" out the try ... catch, as there is nothing
to try.

Example of a domain object (seat of pants, no design):

public class User

{

public User()

{

}

public User(int userID)

{

}



private int _userId;

//Other internal variables here



public property UserId

{

get

{

return _userId;

}

set

{

_userId = value;

}

}



//Other properties here



public void Fill()

{

//work done to get user inforamtion

}



public void Fill(int userId)

{

UserId = userId;

//chained method to avoid duplicate work

Fill();

}

}



Calling this with MAJOR bug:



try

{

using(User u = new User(1)){}
}

catch
{
}

1. What is there to catch?
2. When are you going to USE the object?

If you actually provide something to catch by triggering behavior on the
constructor, you are creating an object that moves on start (imagine if your
car did this to see why it is not advised).

If, instead, you USE the object, the BUG disappears.

This means you either decide to USE the object (no bug) or have an
improperly set up object (bad code). If you prefer writing bad code, I can
see how this is a MAJOR BUG.

Should the bug be fixed? Yes, an apparently has in 2.0.
Should code be fixed that actually encounters this particular bug? Yes, as
it is badly designed.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***********************************************
Think Outside the Box!
***********************************************
 
Back
Top