Runtime Error Java

For problem Merge two sorted lists, below is the code: I can’t find an issue but code drills even the test run is giving runtime error?

import java.util.*;

// Custom list node. DO NOT MODIFY.
class ListNode<T> {
public T value;
public ListNode<T> next;
ListNode(T value) {
	this.value = value;

class MergeSortedLists {
public ListNode<Integer> getMergedList(ListNode<Integer> list1, ListNode<Integer> list2) {
	if(null == list1)
		return list2;
	if(null == list2)
		return list1;

	ListNode<Integer> ans = new ListNode<Integer>(Integer.valueOf(0)); = null;

	while(null != list1 && null != list2){

		if(list1.value < list2.value){ = list1;
			list1 =;
		else{ = list2;
			list2 =;


	if(list1 != null) list1;

	if(list2 != null) = list2;


1 Like

There was a bug in the automatic I/O code for lists in Java. It is now fixed and this code doesn’t give runtime error.

Thanks for reporting the bug!

1 Like

Thanks for the quick resolution