-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a race condition in Derived Field parsing from search request
Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com>
- Loading branch information
1 parent
f5dbbb0
commit c77b334
Showing
5 changed files
with
65 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
server/src/main/java/org/opensearch/common/util/CopyUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.util; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CopyUtil { | ||
|
||
public static Object deepCopy(Object value) { | ||
if (value instanceof Map) { | ||
Map<?, ?> mapValue = (Map<?, ?>) value; | ||
Map<Object, Object> copy = new HashMap<>(mapValue.size()); | ||
for (Map.Entry<?, ?> entry : mapValue.entrySet()) { | ||
copy.put(entry.getKey(), deepCopy(entry.getValue())); | ||
} | ||
return copy; | ||
} else if (value instanceof List) { | ||
List<?> listValue = (List<?>) value; | ||
List<Object> copy = new ArrayList<>(listValue.size()); | ||
for (Object itemValue : listValue) { | ||
copy.add(deepCopy(itemValue)); | ||
} | ||
return copy; | ||
} else if (value instanceof byte[]) { | ||
byte[] bytes = (byte[]) value; | ||
return Arrays.copyOf(bytes, bytes.length); | ||
} else if (value == null | ||
|| value instanceof Byte | ||
|| value instanceof Character | ||
|| value instanceof Short | ||
|| value instanceof String | ||
|| value instanceof Integer | ||
|| value instanceof Long | ||
|| value instanceof Float | ||
|| value instanceof Double | ||
|| value instanceof Boolean | ||
|| value instanceof ZonedDateTime) { | ||
return value; | ||
} else if (value instanceof Date) { | ||
return ((Date) value).clone(); | ||
} else { | ||
throw new IllegalArgumentException("unexpected value type [" + value.getClass() + "]"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters