Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-1423

ObjectFactory$ObjectEqualsComparator.equals throws NPE if second arg is null

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Duplicate Issue
    • Affects Version/s: 4.0.4
    • Fix Version/s: 4.0.5, 5.0.0.M1
    • Component/s: None
    • Labels:
      None
    • Workaround Description:
      Hide

      change the method as:

      protected static class ObjectEqualsComparator {

      // trying to implement runtime type coercion
      public boolean equals( Object arg0, Object arg1 ) {
      if ( arg0 == null )

      { return arg1 == null; }

      // handle arg0 != null && arg1 == null
      if (arg1 == null) return false;

      if( arg1 != null && arg1 instanceof ShadowProxy )

      { return arg1.equals( arg0 ); }

      if( arg0 instanceof Number ){
      double val0 = ((Number) arg0).doubleValue();
      double val1 = 0;
      if( arg1 instanceof Number )

      { val1 = ((Number) arg1).doubleValue(); }

      else if( arg1 instanceof String )

      { val1 = Double.parseDouble( ( String ) arg1 ); }

      else

      { System.err.println("arg0: '"+arg0+"', arg1: '"+arg1+"'"); throw new ClassCastException( "Not possible to convert "+arg1.getClass()+" into a double value to compare it to "+arg0.getClass() ); }

      return val0 == val1; // in the future we may need to handle rounding errors
      }
      if( arg0 instanceof String )

      { return arg0.equals( arg1.toString() ); }

      if( arg0 instanceof Boolean ) {
      if( arg1 instanceof String )

      { return ((Boolean)arg0).booleanValue() == Boolean.valueOf( (String)arg1 ).booleanValue(); }

      }
      if( arg0 instanceof Character ) {
      if( arg1 instanceof String && ((String) arg1).length() == 1 )

      { return ((Character)arg0).charValue() == ((String)arg1).charAt( 0 ); }

      }
      return arg0.equals( arg1 );
      }
      }

      Show
      change the method as: protected static class ObjectEqualsComparator { // trying to implement runtime type coercion public boolean equals( Object arg0, Object arg1 ) { if ( arg0 == null ) { return arg1 == null; } // handle arg0 != null && arg1 == null if (arg1 == null) return false; if( arg1 != null && arg1 instanceof ShadowProxy ) { return arg1.equals( arg0 ); } if( arg0 instanceof Number ){ double val0 = ((Number) arg0).doubleValue(); double val1 = 0; if( arg1 instanceof Number ) { val1 = ((Number) arg1).doubleValue(); } else if( arg1 instanceof String ) { val1 = Double.parseDouble( ( String ) arg1 ); } else { System.err.println("arg0: '"+arg0+"', arg1: '"+arg1+"'"); throw new ClassCastException( "Not possible to convert "+arg1.getClass()+" into a double value to compare it to "+arg0.getClass() ); } return val0 == val1; // in the future we may need to handle rounding errors } if( arg0 instanceof String ) { return arg0.equals( arg1.toString() ); } if( arg0 instanceof Boolean ) { if( arg1 instanceof String ) { return ((Boolean)arg0).booleanValue() == Boolean.valueOf( (String)arg1 ).booleanValue(); } } if( arg0 instanceof Character ) { if( arg1 instanceof String && ((String) arg1).length() == 1 ) { return ((Character)arg0).charValue() == ((String)arg1).charAt( 0 ); } } return arg0.equals( arg1 ); } }

      Description

      org.drools.base.evaluators.ObjectFactory$ObjectEqualsComparator.equals throws NPE if arg0 != null and arg1 == null.

      protected static class ObjectEqualsComparator {

      // trying to implement runtime type coercion
      public boolean equals( Object arg0, Object arg1 ) {

      ....

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  tirelli Edson Tirelli
                  Reporter:
                  pgras Patrick Gras
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: