groovy
  1. groovy
  2. GROOVY-5031

MOP: Exceptions thrown by setters of closure delegate objects are ignored; values end up in the binding

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Incomplete
    • Affects Version/s: 1.7.10
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      JDK 1.6
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      // Java delegate class
      public class TheDelegate {
             public void setDelegatesPropertyThrowsException(Object value)
                     throws javax.mail.internet.AddressException
             {
                     throw new AddressException("Just an example.");
             }
      }
      
      
      // the closure call (Java)
      public void methodThatTakesAClosure(Closure cl) {
             final TheDelegate delegate = new TheDelegate();
      
             // ...
      
             closure = (Closure)cl.clone();
             closure.setResolveStrategy(Closure.DELEGATE_FIRST);
             closure.setDelegate(delegate);
             closure.call(delegate); // no exception is seen here
      
             // ...
      }
      

      The following script does not get the exception thrown by setDelegatesPropertyThrowsException.

      // Groovy script
      thing.methodThatTakesAClosure {
             delegatesPropertyThrowsException = "tryThis"
      }
      
      assert delegatesPropertyThrowsException == "tryThis" // this was the MOP's second try
      

        Activity

        Hide
        Alexander Veit added a comment -

        The empty description was submitted by accident. Since I cannot edit it, it comes here...

        // Java delegate class
        public class TheDelegate {
        	public void setDelegatesPropertyThrowsException(Object value)
        		throws javax.mail.internet.AddressException
        	{
        		throw new AddressException("Just an example.");
        	}
        }
        
        
        // the closure call (Java)
        public void methodThatTakesAClosure(Closure cl) {
        	final TheDelegate delegate = new TheDelegate();
        
        	// ...
        	
        	closure = (Closure)cl.clone();
        	closure.setResolveStrategy(Closure.DELEGATE_FIRST);
        	closure.setDelegate(delegate);
        	closure.call(delegate); // no exception is seen here
        
        	// ...
        }
        

        The following script does not get the exception thrown by setDelegatesPropertyThrowsException.

        // Groovy script
        thing.methodThatTakesAClosure {
        	delegatesPropertyThrowsException = "tryThis"
        }
        
        assert delegatesPropertyThrowsException == "tryThis" // this was the MOP's second try
        
        Show
        Alexander Veit added a comment - The empty description was submitted by accident. Since I cannot edit it, it comes here... // Java delegate class public class TheDelegate { public void setDelegatesPropertyThrowsException( Object value) throws javax.mail.internet.AddressException { throw new AddressException( "Just an example." ); } } // the closure call (Java) public void methodThatTakesAClosure(Closure cl) { final TheDelegate delegate = new TheDelegate(); // ... closure = (Closure)cl.clone(); closure.setResolveStrategy(Closure.DELEGATE_FIRST); closure.setDelegate(delegate); closure.call(delegate); // no exception is seen here // ... } The following script does not get the exception thrown by setDelegatesPropertyThrowsException. // Groovy script thing.methodThatTakesAClosure { delegatesPropertyThrowsException = "tryThis" } assert delegatesPropertyThrowsException == "tryThis" // this was the MOP's second try
        Hide
        Roshan Dawrani added a comment -

        I couldn't reproduce the error with Groovy 1.7.10. It correctly threw the exception for me.

        Also, does it have anything to do with GroovyScriptEngine (the component chosen for the bug)? The sample code shows no relation to it.

        Show
        Roshan Dawrani added a comment - I couldn't reproduce the error with Groovy 1.7.10. It correctly threw the exception for me. Also, does it have anything to do with GroovyScriptEngine (the component chosen for the bug)? The sample code shows no relation to it.

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Alexander Veit
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: