Yet another Major JIT Optimizer BUG

C

Cowboy \(Gregory A. Beamer\)

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!
***********************************************
 
C

Cowboy \(Gregory A. Beamer\)

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!
***********************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top