Announcement

Collapse
No announcement yet.

[FIXED] [#3612] NullReferenceException when pass null into a nullable enum parameter

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    [FIXED] [#3612] NullReferenceException when pass null into a nullable enum parameter

    Hi

    I came across a bug which currenlty blocks our internal development. The bug seems to exists since at least V16.5 all the way up to 17.1.
    Reproduction:

        public enum Mode
        {
            Slow,
            Medium,
            Fast
        }
    
        public class Program
        {
            public static void Main()
            {
                SetModeStronglyTyped(null);
            }
    
            public static void SetModeStronglyTyped(Mode? mode)
            {
                SetMode(mode);
            }
    
            public static void SetMode(object mode)
            {
    
                Console.WriteLine(mode ?? "Null");
            }
        }
    1. Run the above sample in a real Bridge.NET project (NOT in deck.net !!)
    2. Open index.html -> You will notice the console error (see attached Console.txt)
    3. Switch off boxing in bridge.json
    4. Recompile
    5. Now the sample works as expected
    In brief: When in boxing-mode, bridge cannot handle nullable enums when the passed value equals null.

    The sample works fine on deck.net, so don't try to reproduce the bug there. I suspect that you have boxing turned off by default in deck.net!?

    We managed to work around the problem by turning off boxing, but we're worried that this might pose other problems down the road. BTW I'm still not sure about the whole boxing pro/contra arguments. Do you have an article sheding some light on this?

    Thanks,
    Marco
    Attached Files
    Last edited by fabricio.murta; 2018-06-04 @ 08:30 PM.

    #2
    Hi Marco,

    Thanks for reporting this issue and providing nice reproduce steps. Should be relatively easy to fix - we'll get back to you once we have some progress on that.

    Regarding Deck.NET - your suggestion about boxing setting is correct. Anyways we can still use [Rules] attribute to configure those settings. I've created a Deck for the sample above:
    https://deck.net/3856bbc6c0a0e14fb86ab0f2beafa40e

    I'm still not sure about the whole boxing pro/contra arguments. Do you have an article sheding some light on this?
    I believe boxing feature is required to mimic .NET behavior in JavaScript. Consider the scenario below, without boxing in place it outputs a different string. Unfortunately, there are not much information documented. The start point could be Issue #2077, you might be also interested in [Unbox] attribute.

    https://deck.net/3a2502e86e32ceec3007162a02a98763

    //[Rules(Boxing = BoxingRule.Managed)]
    public class Program
    {
        public static void Main()
        {
            int val = 5;
    
            object boxed1 = val;
            object boxed2 = val;
    
            var areEqual = boxed1 == boxed2;
    
            // .NET will print "False" here:
            Console.WriteLine("Boxed values are equal: " + areEqual);
        }
    }



    Comment


      #3
      Hello! Andrey created issue #3612 to track this defect and a fix has already been submitted for review! I've updated the issue title dropping the 'urgent' prefix, as it does not really add up to the report anyway (and we need room to add the issue number and status).

      Hope you understand!

      Comment


        #4
        Fixed! The fix will make it live next Bridge release!

        Currently that would be version 17.2.0, but it may change if for some reason we need to release under a different version number.

        Comment

        Working...
        X