Finding the second largest element of large input sets
So your code seems to work fine, but you get a non-zero exit code for some unknown inputs... What could go wrong? If I call out to you 100 numbers, do you need to remember all of them to tell me the second highest? (inside an array in your head) 
You don't. And the program doesn't either.
Most probably the program crashes with an out of memory error.

Here's one way to solve this using constant storage:

    while (testcase-- &gt; 0) {
        long num;
        long largest = Long.MIN_VALUE;
        long secondLargest = Long.MIN_VALUE;
        while ((num = sc.nextLong()) != -1) {



                  if (num > largest) {
                     secondLargest = largest;
                     largest = num;
                } else if (num > secondLargest) {
                     secondLargest = num;
                }  


        }
        System.out.println(secondLargest);
    }


Code review

Your code had serious formatting issues. Cleaned up, your code would look like this:

    while (testcase-- &gt; 0) {
        List&lt;Long&gt; numbers = new ArrayList&lt;&gt;();
        long num;
        while ((num = sc.nextLong()) != -1) {
            numbers.add(num);
        }
        Collections.sort(numbers);
        if (numbers.size() == 0) {
            System.err.println("");
        } else if (numbers.size() == 1) {
            System.out.println(numbers.get(0));
        } else {
            System.out.println(numbers.get(numbers.size() - 2));
        }
    }


What changed?


Formatting fixed
Use interface type instead of implementation (List)
Removed redundant variables
Removed redundant initializations
Removed redundant parentheses
Improved variable names