Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 606234 Details for
Bug 850744
assertEquals() fails in the CLI on native javascript arrays in JDK7
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
proposed patch
bz850744.patch (text/plain), 5.11 KB, created by
Lukas Krejci
on 2012-08-22 12:18:36 UTC
(
hide
)
Description:
proposed patch
Filename:
MIME Type:
Creator:
Lukas Krejci
Created:
2012-08-22 12:18:36 UTC
Size:
5.11 KB
patch
obsolete
>diff --git a/modules/enterprise/binding/src/main/java/org/rhq/bindings/util/ScriptAssert.java b/modules/enterprise/binding/src/main/java/org/rhq/bindings/util/ScriptAssert.java >index 15ed37c..c218c93 100644 >--- a/modules/enterprise/binding/src/main/java/org/rhq/bindings/util/ScriptAssert.java >+++ b/modules/enterprise/binding/src/main/java/org/rhq/bindings/util/ScriptAssert.java >@@ -24,6 +24,7 @@ > package org.rhq.bindings.util; > > import java.lang.reflect.Array; >+import java.lang.reflect.Field; > import java.util.ArrayList; > import java.util.Arrays; > import java.util.Collection; >@@ -115,16 +116,74 @@ public class ScriptAssert { > return; > } > if (expected != null) { >- if (expected.getClass().isArray()) { >- assertArrayEquals(actual, expected, msg); >+ // this is a temporary workaround for the difference between the Rhino bundled with JDK6 and JDK7 >+ // (which we both need to support). >+ // In JDK6 the NativeArray doesn't implement the java.util.Collection and thus we need >+ // assertEquals(Object[], Object[]). >+ // But that would cause errors on JDK7 because NativeArray's in there DO implement java.util.Collection >+ // and thus in JDK7 Rhino barfs because it can't decide with method to use - Object[] or Collection? >+ // >+ // At the same time we DO need assertEquals(Collection, Collection) because many of the types that get >+ // returned from RHQ server are ordinary Java objects and thus passing to only assertEquals(Object, Object) >+ // would potentially change the behavior. >+ // >+ // And so we need to resort to this ugly hack (note that is will be NO LONGER needed in RHQ 4.5.0 because in there >+ // we are using our own script engine and therefore are more in control of what gets passed how). >+ Object[] actualArray = actual == null ? null : extractArray(actual); >+ Object[] expectedArray = extractArray(expected); >+ >+ if (actualArray == null) { >+ //we could not convert "actual" to a java array >+ if (expectedArray == null) { >+ //both are most probably not arrays >+ expected.equals(actual); >+ } else { >+ //expected is an array, actual not >+ failNotEquals(actual, expected, msg); >+ } > return; >- } else if (expected.equals(actual)) { >+ } else { >+ if (expectedArray == null) { >+ //actual is an array, expected not >+ failNotEquals(actual, expected, msg); >+ } else { >+ assertArrayEquals(actualArray, expectedArray, msg); >+ } > return; > } > } > failNotEquals(actual, expected, msg); > } > >+ /** >+ * This is a helper method to {@link #assertEquals(Object, Object, String)} that can extract an array value >+ * for either a java or javascript array. >+ * <p> >+ * This method is not necessary in RHQ-4.5.0 and later codebases (in case anyone tried to merge this into mainline codebase >+ * or the other way round). >+ * >+ * @param object >+ * @return >+ */ >+ private static Object[] extractArray(Object object) { >+ Class<?> cls = object.getClass(); >+ >+ if (cls.isArray()) { >+ return (Object[]) object; >+ } else if (cls.getName().equals("sun.org.mozilla.javascript.internal.NativeArray")) { >+ try { >+ Field dense = cls.getDeclaredField("dense"); >+ dense.setAccessible(true); >+ >+ return (Object[]) dense.get(object); >+ } catch (Exception e) { >+ //just fail in this case >+ } >+ } >+ >+ return null; >+ } >+ > /** > * <b>COPIED FROM TESTNG</b> > * Asserts that two objects are equal. It they are not, an AssertionError, >@@ -245,21 +304,6 @@ public class ScriptAssert { > } > } > >- public void assertEquals(Object[] actual, Object[] expected, String msg) { >- if (actual == expected) { >- return; >- } >- >- if ((actual == null && expected != null) || (actual != null && expected == null)) { >- if (msg != null) { >- fail(msg); >- } else { >- fail("Arrays not equal: " + Arrays.toString(expected) + " and " + Arrays.toString(actual)); >- } >- } >- assertEquals(Arrays.asList(actual), Arrays.asList(expected), msg); >- } >- > public void assertEqualsNoOrder(Object[] actual, Object[] expected, String msg) { > if (actual == expected) { > return; >@@ -288,10 +332,6 @@ public class ScriptAssert { > } > } > >- public void assertEquals(Object[] actual, Object[] expected) { >- assertEquals(actual, expected, null); >- } >- > public void assertEqualsNoOrder(Object[] actual, Object[] expected) { > assertEqualsNoOrder(actual, expected, null); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 850744
: 606234