Skip to content

Commit 5de6cf2

Browse files
jerryshaoalex-the-man
authored andcommitted
LIVY-236. Fix NPE issue in Job API when return value is Void
Closes #215
1 parent 3c5cf79 commit 5de6cf2

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

client-http/src/main/java/com/cloudera/livy/client/http/JobHandleImpl.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ public void run() {
235235

236236
switch (status.state) {
237237
case SUCCEEDED:
238-
@SuppressWarnings("unchecked")
239-
T localResult = (T) serializer.deserialize(ByteBuffer.wrap(status.result));
240-
result = localResult;
238+
if (status.result != null) {
239+
@SuppressWarnings("unchecked")
240+
T localResult = (T) serializer.deserialize(ByteBuffer.wrap(status.result));
241+
result = localResult;
242+
}
241243
finished = true;
242244
break;
243245

integration-test/src/test/scala/com/cloudera/livy/test/JobApiIT.scala

+7
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ class JobApiIT extends BaseIntegrationTestSuite with BeforeAndAfterAll with Logg
190190
assert(result === "foo")
191191
}
192192

193+
test("return null should not throw NPE") {
194+
assume(client2 != null, "Client not active")
195+
196+
val result = waitFor(client2.submit(new VoidJob()))
197+
assert(result === null)
198+
}
199+
193200
test("destroy the session") {
194201
assume(client2 != null, "Client not active.")
195202
client2.stop(true)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to Cloudera, Inc. under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. Cloudera, Inc. 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, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.cloudera.livy.test.jobs;
20+
21+
import com.cloudera.livy.Job;
22+
import com.cloudera.livy.JobContext;
23+
24+
public class VoidJob implements Job<Void> {
25+
@Override
26+
public Void call(JobContext jc) {
27+
return null;
28+
}
29+
}

0 commit comments

Comments
 (0)