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

[CARBONDATA-3300] Fixed ClassNotFoundException when using UDF in spark-shell #3132

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.carbondata.core.metadata.blocklet.datachunk.DataChunk;
import org.apache.carbondata.core.metadata.blocklet.index.BlockletIndex;

import org.apache.commons.io.input.ClassLoaderObjectInputStream;
import org.apache.hadoop.io.Writable;

/**
Expand Down Expand Up @@ -261,7 +262,8 @@ private byte[] serializeDataChunk(DataChunk chunk) throws IOException {

private DataChunk deserializeDataChunk(byte[] bytes) throws IOException {
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
ObjectInputStream inputStream = new ObjectInputStream(stream);
ObjectInputStream inputStream =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method seems that "inputStream.close();" doesn't use finally block, can you add the protection in this pr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not open the file to mandatorily close the stream, it just opens on the byte[] so it is not needed to close in finally

new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(), stream);
DataChunk dataChunk = null;
try {
dataChunk = (DataChunk) inputStream.readObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import com.google.gson.GsonBuilder;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.input.ClassLoaderObjectInputStream;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringEscapeUtils;
Expand Down Expand Up @@ -1536,7 +1537,8 @@ public static ValueEncoderMeta deserializeEncoderMetaV2(byte[] encoderMeta) {
ValueEncoderMeta meta = null;
try {
aos = new ByteArrayInputStream(encoderMeta);
objStream = new ObjectInputStream(aos);
objStream =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"CarbonUtil.closeStreams(objStream);" cann't be called when not IOException

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for other exception handling because stream throw only ClassNotFoundException/IOException.

new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(), aos);
meta = (ValueEncoderMeta) objStream.readObject();
} catch (ClassNotFoundException e) {
LOGGER.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.apache.carbondata.common.logging.LogServiceFactory;

import org.apache.commons.io.input.ClassLoaderObjectInputStream;
import org.apache.log4j.Logger;

/**
Expand Down Expand Up @@ -94,7 +95,7 @@ public static Object convertStringToObject(String objectString) throws IOExcepti
try {
bais = new ByteArrayInputStream(bytes);
gis = new GZIPInputStream(bais);
ois = new ObjectInputStream(gis);
ois = new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(), gis);
return ois.readObject();
} catch (ClassNotFoundException e) {
throw new IOException("Could not read object", e);
Expand Down