jdereg / java-util Goto Github PK
View Code? Open in Web Editor NEWRare, hard-to-write utilities that are thoroughly tested
License: Apache License 2.0
Rare, hard-to-write utilities that are thoroughly tested
License: Apache License 2.0
I try to use your library for communicate client server via RMI, but GraphComparator.Delta isn't Serialized. Can you explain why it isn't Serialized?
Unfortunately, hashCodes are not intended to be unique, so it's possible that two keys would have the same hash and the second will overwrite the first. In a Map with 110 entries using unique 4 char Strings, I found 4 keys with duplicate hashes.
At that point what you're really after is a unique id for each Object (key). This would fix the above problem but I just realised there is a more fundamental problem with the idea of trying to compare Maps in general: There might be cases where you consider two keys in a map to be deeply equal, but Java does not consider them equal, hence it's possible to have them both in the same Map. At that point, you're conflicting with the principle of the same key in a Map always resolving to the same value. Maybe at that point you can compare the Set of values the equal keys map to but that's skirting on the edges of what a Map really is...
We try to use you GraphComparator to compare two complex objects each other.
For a simple object it is working really good, but I'm not able to get it work with properties which are an List of other Complex Objects which could contain again a complex object.
Let me explain better, if we have for Example this object (we will represent it for simplicity by an json object):
{
"id": 1,
"name": "Master1",
"details": [{
"id": 1,
"name": "Master1.Detail1"
}, {
"id": 2,
"name": "Master2.Detail2",
"subDetail": [{
"id1": 1,
"name": "Master2.Detail2.SubDetail1"
}]
}]
}
In This Case if we change name
in SubDetail1
and compare old with new object we need also to be notified that the property in the third level of 3 complex objects changed.
Is this possible with you library? Can we do a workaround to get it work?
I am having a problem while using your great library as I want to compare two ArrayLists for differences using GraphComparator. I deleted an element of one of the lists and when I compared the old list and new list it shows that there is OBJECT_ORPHAN command. But when I reversed it by comparing the new list and the old list, it should show that there is a new object but somehow it could not detect.
My code is like this:
List<UnifiedBucket> ubs= new ArrayList<>(); // Assume I already put elements in the list
List<UnifiedBucket> ubsCopy = cloner.deepClone(ubs);
ubsCopy.remove(25);
ubsCopy.get(14).setRawPolicy(null);
List<GraphComparator.Delta> deltas = GraphComparator.compare(ubs, ubsCopy, getIdFetcher()); //This works fine as I could find the OBJECT_ORPHAN
for (GraphComparator.Delta delta : deltas) {
if (delta.getCmd() != GraphComparator.Delta.Command.LIST_SET_ELEMENT) {
System.out.println(delta);
}
}
List<GraphComparator.Delta> deltas2 = GraphComparator.compare(ubsCopy, ubs, getIdFetcher()); //This does not work fine as I could not find the new element that is not deleted in the ubs list
for (GraphComparator.Delta delta : deltas2) {
if (delta.getCmd() != GraphComparator.Delta.Command.LIST_SET_ELEMENT) {
System.out.println(delta);
}
}
Any reason why?
You are using a version of log4j, that has a known vulnerability:
https://nvd.nist.gov/vuln/search/results?form_type=Advanced&results_type=overview&search_type=all&cpe_vendor=cpe%3A%2F%3Aapache&cpe_product=cpe%3A%2F%3Aapache%3Alog4j&cpe_version=cpe%3A%2F%3Aapache%3Alog4j%3A2.5
Could you please update to a more recent version?
Hi! For a not-so-legacy code i've to use java8, but if I try to use this library i receive this error:
java: cannot access com.cedarsoftware.util.GraphComparator
bad class file: /.m2/repository/com/cedarsoftware/java-util/2.0.0/java-util-2.0.0.jar!/com/cedarsoftware/util/GraphComparator.class
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
I must use an older version? GraphComparator has the same features?
The following test fails
test() {
Class1 x = new Class1(true, Math.tan(Math.PI / 4), 1);
Class1 y = new Class1(true, 1.0, 1);
assertTrue(DeepEquals.deepEquals(x, y));
}
class Class1 {
private boolean b;
private double d;
int i;
public Class1(boolean b, double d, int i) {
super();
this.b = b;
this.d = d;
this.i = i;
}
}
The comparison of two SortedSet
s or SortedMap
s with deepEquals
does not work as expected, when the SortedSet
s or SortedMap
s are not using the same comparator for ordering the elements. If not the same comparators are used, the method returns wrong results, as the iterators i1
and i2
used in compareOrderedCollection
and compareSortedMap
return elements in a different order.
With the default implementation of equals
, this is not the case:
SortedMap<String, String> map1 = new TreeMap<>(Comparator.naturalOrder());
map1.put("a", "b");
map1.put("c", "d");
SortedMap<String, String> map2 = new TreeMap<>(Comparator.reverseOrder());
map2.put("a", "b");
map2.put("c", "d");
System.out.println(map1.equals(map2)); // true
In the JDK, the equals
method of Set
s and Map
s does not consider the ordering in any case, even for SortedSet
s and SortedMap
s. Instead SortedSet
s are considered to be equal to Set
s (and respectively for Map
s) when they contain exactly the same entries:
SortedSet<String> set1 = new TreeSet<>();
Set<String> set2 = new HashSet<>();
System.out.println(set1.equals(set2)); // true
Whereas deepEquals
considers those two Set
s to be not equal, because they are not both of the type SortedSet
s.
As people use deepEquals in unit testing, things are occasionally going to not be deep equals, and something better than assertTrue() is needed. If not another arg, then whatever is needed to deliver assertDeepEquals(a,b) that'd throw exceptions that are helpful to debuggers :)
There seem to be some issues with DeepEquals in the handling of isContained within compareUnorderedCollection/compareUnorderedMap (i.e. colliding hashcode values):
a) Options (IGNORE_CUSTOM_EQUALS and ALLOW_STRINGS_TO_MATCH_NUMBERS) are not propagated.
b) When progagating options the Set of visited ItemsToCompare (or a copy if it) should be passed on to prevent StackOverFlow from occurring.
Hello,
I'm trying to use your java-util in a OSGi environment and I found out that the library is not an OSGi bundle so I made some changes to make it a proper OSGi bundle and I'll submit a PR soon but I need some info:
Is there a reason for the two point above ?
The security risk with Log4j has been termed as CVE-2021-44228 in Log4j Ref- https://logging.apache.org/log4j/2.x/security.html.In order to address this vulnerabilities log4j version needs to be upgraded. Can the log4j dependency version used java-util be upgraded to 2.1.15 or above ?
Option to use whole JSON path in the fieldName in GraphComparator.
This would be greatly appreciated, because when having the same field names as leafs in different document branches, it's not obvious which one is shown.
In some cases it might be nice if we can support this use case
public void testOrderedCollection() {
List<String> a = Lists.newArrayList("one", "two", "three", "four",
"five");
List<String> b = Lists.newLinkedList(a);
assertTrue(DeepEquals.deepEquals(a, b));
}
Hi
The following source files are without license headers:
./src/main/java/com/cedarsoftware/util/ProxyFactory.java
./src/test/java/com/cedarsoftware/util/TestByteUtilities.java
./src/test/java/com/cedarsoftware/util/TestDateUtilities.java
./src/test/java/com/cedarsoftware/util/TestExceptionUtilities.java
./src/test/java/com/cedarsoftware/util/TestHandshakeException.java
./src/test/java/com/cedarsoftware/util/TestInetAddressUnknownHostException.java
./src/test/java/com/cedarsoftware/util/TestProxyFactory.java
./src/test/java/com/cedarsoftware/util/TestStringUtilities.java
./src/test/java/com/cedarsoftware/util/TestUrlInvocationHandlerWhenExceptionsAreThrown.java
./src/test/java/com/cedarsoftware/util/TestUrlInvocationHandlerWithPlainReader.java
Please, confirm the licensing of code and/or content/s, and add license headers.
Thanks in advance
Regards
Hello, we use com.cedarsoftware.util.GraphComparator to find differences between two objects. Running the code with java 11 we get a warning while access private static final field "serialVersionUID". I would expect that static final fields are skipped from comparison.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.cedarsoftware.util.ReflectionUtils (file:......../files-2.1/com.cedarsoftware/java-util/2.0.0/7cdce491c29122dc4a959a69f51064ef63eed31/java-util-2.0.0.jar) to field java.util.UUID.serialVersionUID
WARNING: Please consider reporting this to the maintainers of com.cedarsoftware.util.ReflectionUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Thank you
Eddi
I believe this issue still persists when GraphComparator::deepEquals
is used. Set comparisons are failing but UnorderedMap comparison with a dummy value succeed
Hi,
I have found a possible issue in DeepEquals utility. It's possible to use the IGNORE_CUSTOM_EQUALS options (if you don't want to use custom equals implementation for specific classes). This option should be Set as it's loaded from options Map on line 176 in DeepEquals utility. But if you look at usage of this set the input parameter of contains method is Class on line 361 (it always be false if any class should be "blacklisted").
Thx.
JS
public static void main(String[] args) {
class Foo {}
System.out.println(DeepEquals.deepEquals(new ArrayList<String>(), new Foo())); //this print `false`, as expected
System.out.println(DeepEquals.deepEquals(new Foo(), new ArrayList<String>())); //but this print `true`
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.