T6410643.java revision 1732:e39669aea0bd
110216Sphk/*
210216Sphk * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
310216Sphk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
410216Sphk *
510216Sphk * This code is free software; you can redistribute it and/or modify it
610216Sphk * under the terms of the GNU General Public License version 2 only, as
710216Sphk * published by the Free Software Foundation.
810216Sphk *
910216Sphk * This code is distributed in the hope that it will be useful, but WITHOUT
1010216Sphk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1110216Sphk * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1210216Sphk * version 2 for more details (a copy is included in the LICENSE file that
1310216Sphk * accompanied this code).
1410216Sphk *
1510216Sphk * You should have received a copy of the GNU General Public License version
1610216Sphk * 2 along with this work; if not, write to the Free Software Foundation,
1710216Sphk * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1810216Sphk *
1910216Sphk * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2010216Sphk * or visit www.oracle.com if you need additional information or have any
2110216Sphk * questions.
2210216Sphk */
2310216Sphk
2410216Sphk/*
2510216Sphk * @test
2610216Sphk * @bug     6410643
2710216Sphk * @summary JSR 199: The method JavaCompilerTool.run fails to handle null arguments
2810216Sphk * @author  Peter von der Ah\u00e9
2910216Sphk * @library ../lib
3010216Sphk * @build ToolTester
3110216Sphk * @run main T6410643
3210216Sphk */
3310216Sphk
3410216Sphkimport javax.tools.JavaFileObject;
3510216Sphkimport static java.util.Collections.singleton;
3610216Sphk
3710216Sphkpublic class T6410643 extends ToolTester {
3810216Sphk
3910216Sphk    void testGetTask(Iterable<String> options,
4010216Sphk                     Iterable<String> classes,
4110216Sphk                     Iterable<? extends JavaFileObject> compilationUnits) {
4210216Sphk        try {
4310216Sphk            task = tool.getTask(null, null, null, null, null, singleton((JavaFileObject)null));
4410216Sphk            throw new AssertionError("Error expected");
4510216Sphk        } catch (NullPointerException e) {
4610216Sphk            System.err.println("Expected error occurred: " + e);
4710216Sphk        }
4810216Sphk    }
4910216Sphk
5010216Sphk    void test(String... args) {
5110216Sphk        task = tool.getTask(null, null, null, null, null, null);
5210216Sphk        if (task.call())
5310216Sphk            throw new AssertionError("Error expected");
5410216Sphk        System.err.println("Compilation failed as expected!");
5510216Sphk        Iterable<String>         s = singleton(null);
5610216Sphk        Iterable<JavaFileObject> f = singleton(null);
5710216Sphk        //    case (null, null, null) is tested above
5810216Sphk        testGetTask(null, null, f);
5910216Sphk        testGetTask(null, s,    null);
6010216Sphk        testGetTask(null, s,    f);
6110216Sphk        testGetTask(s,    null, null);
6210216Sphk        testGetTask(s,    null, f);
6310216Sphk        testGetTask(s,    s,     null);
6410216Sphk        testGetTask(s,    s,    f);
6510216Sphk        System.err.println("Test result: PASSED");
6610216Sphk    }
6710216Sphk    public static void main(String... args) {
6810216Sphk        new T6410643().test(args);
6910216Sphk    }
7010216Sphk}
7110216Sphk