Skip to content

Commit

Permalink
Never use String#getBytes() in the production code (facebook#9487)
Browse files Browse the repository at this point in the history
Summary:
There are encodings that are not ASCII-compatible (like cp1140), so it is possible that a JVM is run with a default encoding in which String#getBytes() would return unexpected values even for ASCII strings.

A little bit of context: https://stackoverflow.com/questions/70913929/can-an-encoding-incompatible-with-ascii-encoding-be-set-as-a-default-encoding-in/70914154

Pull Request resolved: facebook#9487

Reviewed By: riversand963

Differential Revision: D34097728

fbshipit-source-id: afd654ecaf20f6d30d9fc20c6a090398de2585eb
  • Loading branch information
rpuch authored and facebook-github-bot committed May 6, 2022
1 parent 736a7b5 commit 00889cf
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion java/src/main/java/org/rocksdb/RocksDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
import java.util.concurrent.atomic.AtomicReference;
import org.rocksdb.util.Environment;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* A RocksDB is a persistent ordered map from keys to values. It is safe for
* concurrent access from multiple threads without any external synchronization.
* All methods of this class could potentially throw RocksDBException, which
* indicates sth wrong at the RocksDB library side and the call failed.
*/
public class RocksDB extends RocksObject {
public static final byte[] DEFAULT_COLUMN_FAMILY = "default".getBytes();
public static final byte[] DEFAULT_COLUMN_FAMILY = "default".getBytes(UTF_8);
public static final int NOT_FOUND = -1;

private enum LibraryState {
Expand Down

0 comments on commit 00889cf

Please sign in to comment.