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

BindingUtils and other database classes should not print the stacktrace #13

Open
kerbymart opened this issue Feb 29, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@kerbymart
Copy link
Member

In the BindingUtils class, the e.printStackTrace(); is used in the deserialize method.

This is not a good practice because it prints the stack trace to the standard error, which is usually the console. This can lead to the leaking of sensitive information such as file paths, server IPs, and other system information.

It's also not flexible in terms of output format and destination. Instead, use a logger to log the exception. This way, the control of the level of logging and it's also more flexible in terms of output format and destination.

public static <T> T deserialize(@NotNull final byte[] data, final Class<T> clazz) {
    try {
        ByteArrayInputStream in = new ByteArrayInputStream(data);
        ObjectInputStream is = new ObjectInputStream(in);
        Object readObject = is.readObject();
        return clazz.isInstance(readObject)
                ? (T) readObject : null;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } catch (ClassNotFoundException e) {
        LOGGER.log(Level.SEVERE, "Deserialization failed", e);
    }
    return null;
}
@kerbymart kerbymart added the enhancement New feature or request label Feb 29, 2024
@kerbymart kerbymart self-assigned this Feb 29, 2024
@kerbymart
Copy link
Member Author

The BindingUtils class is used in the context of JetBrains Xodus to serialize and deserialize objects to and from byte arrays. This is useful when storing complex objects in the Xodus database, which only supports byte arrays as values.

In the LocalTimeRangeBinding, GeoPointBinding, and LocalTimeBinding classes, the BindingUtils.writeObject method is used to serialize an object into a byte array, which is then written to a LightOutputStream. This is part of the process of storing the object in the Xodus database. The BindingUtils.readObject method is used to deserialize a byte array back into an object. This is used when retrieving the object from the Xodus database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant