function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DrBixDrBix 

Bug in code after Spring '12 Release?

I have a piece of code that does this:

 

Integer numBookings = zoneBookingMap.get (zoneId);

numBookings = (numBookings == null) ? 1 : numBookings + 1;

 

This code worked perfectly prior to the release of the recent update.

 

Now, however, numBookings ALWAYS comes back as null!  I tested this by changing the code to:

 

Integer numBookings = zoneBookingMap.get (zoneId);
if (numBookings == null) {
  numBookings = 1;
} else {
  numBookings = numBookings + 1;
}

 

And it fixed the problem.  But this is a huge issue as I use similar code throughout our system.

Best Answer chosen by Admin (Salesforce Developers) 
Greg FeeGreg Fee

Hi DrBix,

 

This is indeed a bug.  Good find!  I am working on a fix as I write this and we'll try to get this out in the next patch (as always, no promises but we'll try out best).  I encourage you to contact your support person to get a case filed just to make sure we get you proper followthrough on getting the fix out, verifying that it solves your issue, etc.  Also, if this is blocking you then you should definitely file a support case as there are potentially other resources we can leverage.

 

Some additional details for you: there is an error in how we do some of the code optimization in the new bytecode-based Apex runtime.  It should only affect the pattern you illustrate below on integers.  The error is that we allow some bytecode ops to get replaced eventhough they are used as the target of a goto and the fix will be to simply disallow that case.  I am a little sad that I didn't have that case already covered.

 

Thanks again for finding this issue and providing a really concise repro.

 

Greg Fee

All Answers

DrBixDrBix

Here is a quick class to demonstrate the issue:

 

public with sharing class TestBug {
    public static void testBug () {
        Integer    test = null;
        System.debug ('test = ' + test);

        test = (test == null) ? 1 : test + 1;

        System.debug ('test = ' + test);

        if (test == null) {
            test = 1;
        } else {
            test = test + 1;
        }

        System.debug ('test = ' + test);
    }
}

Greg FeeGreg Fee

Hi DrBix,

 

This is indeed a bug.  Good find!  I am working on a fix as I write this and we'll try to get this out in the next patch (as always, no promises but we'll try out best).  I encourage you to contact your support person to get a case filed just to make sure we get you proper followthrough on getting the fix out, verifying that it solves your issue, etc.  Also, if this is blocking you then you should definitely file a support case as there are potentially other resources we can leverage.

 

Some additional details for you: there is an error in how we do some of the code optimization in the new bytecode-based Apex runtime.  It should only affect the pattern you illustrate below on integers.  The error is that we allow some bytecode ops to get replaced eventhough they are used as the target of a goto and the fix will be to simply disallow that case.  I am a little sad that I didn't have that case already covered.

 

Thanks again for finding this issue and providing a really concise repro.

 

Greg Fee

This was selected as the best answer
DrBixDrBix

I think it's Decimal objects as well.

DrBixDrBix

Ignore my previous post, it is only Inegers, not Decimals.  My appologies.