Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logical Operators #10

Closed
shrtminded opened this issue Dec 9, 2013 · 2 comments
Closed

Logical Operators #10

shrtminded opened this issue Dec 9, 2013 · 2 comments

Comments

@shrtminded
Copy link

I am receiving a IllegalArgumentException when I have an logical operation.
For example:

if ((1==1) && (2==2)) {
  // do something
}

Cause this exception to be thrown

java.lang.IllegalArgumentException: 164
    at org.kohsuke.groovy.sandbox.impl.Ops.binaryOperatorMethods(Ops.java:29)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedBinaryOp(Checker.java:311)
    at org.kohsuke.groovy.sandbox.impl.Checker$checkedBinaryOp$2.callStatic(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:53)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:157)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:173)

I am not sure if this is related to issue #9.

@shrtminded
Copy link
Author

I was able to fix this issue locally but not sure if this is how you would want to fix it. Below is the patch for the changes I made if you want to use them ...

From 897f595008f18798503e6a339c55c91c4455bb9d Mon Sep 17 00:00:00 2001
Date: Wed, 15 Jan 2014 08:40:21 -0500
Subject: [PATCH] Fixing logical and/or statements

---
 src/main/java/org/kohsuke/groovy/sandbox/impl/Ops.java | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/main/java/org/kohsuke/groovy/sandbox/impl/Ops.java b/src/main/java/org/kohsuke/groovy/sandbox/impl/Ops.java
index 57b3f02..e8fcc62 100644
--- a/src/main/java/org/kohsuke/groovy/sandbox/impl/Ops.java
+++ b/src/main/java/org/kohsuke/groovy/sandbox/impl/Ops.java
@@ -64,6 +64,8 @@ public class Ops {
         b.put(BITWISE_OR,"or");
         b.put(BITWISE_AND,"and");
         b.put(BITWISE_XOR,"xor");
+        b.put(LOGICAL_OR,"or");
+        b.put(LOGICAL_AND,"and");
         b.put(LEFT_SHIFT,"leftShift");
         b.put(RIGHT_SHIFT,"rightShift");
         b.put(RIGHT_SHIFT_UNSIGNED,"rightShiftUnsigned");
-- 
1.8.3.4 (Apple Git-47)

@kohsuke
Copy link
Member

kohsuke commented Jan 16, 2014

I've fixed this issue. The patch is actually incorrect because the "or" method is for overloading bitwise-or, which is not the same thing as logical or.

@kohsuke kohsuke closed this as completed Jan 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants