Skip to content

Commit afd28b9

Browse files
authored
Quality of life fixes for easier hacking (#982)
1 parent 18150fb commit afd28b9

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

common/src/main/java/org/apache/comet/NativeBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static synchronized void load() {
8181

8282
// Try to load Comet library from the java.library.path.
8383
try {
84-
System.loadLibrary(libraryToLoad);
84+
System.loadLibrary(NATIVE_LIB_NAME);
8585
loaded = true;
8686
} catch (UnsatisfiedLinkError ex) {
8787
// Doesn't exist, so proceed to loading bundled library.

native/core/src/jvm_bridge/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fn get_throwable_message(
339339
throwable: &JThrowable,
340340
) -> CometResult<String> {
341341
unsafe {
342-
let message = env
342+
let message: JString = env
343343
.call_method_unchecked(
344344
throwable,
345345
jvm_classes.throwable_get_message_method,
@@ -348,7 +348,11 @@ fn get_throwable_message(
348348
)?
349349
.l()?
350350
.into();
351-
let message_str = env.get_string(&message)?.into();
351+
let message_str = if !message.is_null() {
352+
env.get_string(&message)?.into()
353+
} else {
354+
String::from("null")
355+
};
352356

353357
let cause: JThrowable = env
354358
.call_method_unchecked(
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.comet
21+
22+
import org.apache.spark.SparkException
23+
import org.apache.spark.sql.CometTestBase
24+
import org.apache.spark.sql.catalyst.expressions.PrettyAttribute
25+
import org.apache.spark.sql.comet.{CometExec, CometExecUtils}
26+
import org.apache.spark.sql.types.LongType
27+
import org.apache.spark.sql.vectorized.ColumnarBatch
28+
29+
class CometNativeSuite extends CometTestBase {
30+
test("test handling NPE thrown by JVM") {
31+
val rdd = spark.range(0, 1).rdd.map { value =>
32+
val limitOp =
33+
CometExecUtils.getLimitNativePlan(Seq(PrettyAttribute("test", LongType)), 100).get
34+
val cometIter = CometExec.getCometIterator(
35+
Seq(new Iterator[ColumnarBatch] {
36+
override def hasNext: Boolean = true
37+
override def next(): ColumnarBatch = throw new NullPointerException()
38+
}),
39+
1,
40+
limitOp)
41+
cometIter.next()
42+
cometIter.close()
43+
value
44+
}
45+
46+
val exception = intercept[SparkException] {
47+
rdd.collect()
48+
}
49+
assert(exception.getMessage contains "java.lang.NullPointerException")
50+
}
51+
}

0 commit comments

Comments
 (0)