Skip to content

Commit

Permalink
LIVY-236. Fix NPE issue in Job API when return value is Void
Browse files Browse the repository at this point in the history
Closes apache#215
  • Loading branch information
jerryshao authored and alex-the-man committed Nov 1, 2016
1 parent 3c5cf79 commit 5de6cf2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ public void run() {

switch (status.state) {
case SUCCEEDED:
@SuppressWarnings("unchecked")
T localResult = (T) serializer.deserialize(ByteBuffer.wrap(status.result));
result = localResult;
if (status.result != null) {
@SuppressWarnings("unchecked")
T localResult = (T) serializer.deserialize(ByteBuffer.wrap(status.result));
result = localResult;
}
finished = true;
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ class JobApiIT extends BaseIntegrationTestSuite with BeforeAndAfterAll with Logg
assert(result === "foo")
}

test("return null should not throw NPE") {
assume(client2 != null, "Client not active")

val result = waitFor(client2.submit(new VoidJob()))
assert(result === null)
}

test("destroy the session") {
assume(client2 != null, "Client not active.")
client2.stop(true)
Expand Down
29 changes: 29 additions & 0 deletions test-lib/src/main/java/com/cloudera/livy/test/jobs/VoidJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to Cloudera, Inc. under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Cloudera, Inc. licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cloudera.livy.test.jobs;

import com.cloudera.livy.Job;
import com.cloudera.livy.JobContext;

public class VoidJob implements Job<Void> {
@Override
public Void call(JobContext jc) {
return null;
}
}

0 comments on commit 5de6cf2

Please sign in to comment.