powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Вылетает компилятор с NPE (java 8, на λ'ах (on lambdas))
4 сообщений из 4, страница 1 из 1
Вылетает компилятор с NPE (java 8, на λ'ах (on lambdas))
    #38768696
avp.mk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Однако, здравствуйте!

Main.java
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
package simpleexample;

import java.io.File;
import java.sql.SQLException;
import java.util.List;
import simpleexample.util.FunctionThr;

import static java.lang.System.out;
import static java.util.Arrays.asList;
import static simpleexample.util.NestedDataHandler.handleNestedData_all;

public class Main {

    public static void main(String[] args) throws SQLException {
        File rootDir = new File(".");

        handleNestedData_all(
                rootDir,
                (File dir) -> getNestedElements(dir),
                e -> e, //маппинг не нужен, этот api и так возвращает коллекцию файлов
                File::isDirectory,
                (s, i) -> out.println(s)
        );
    }

    /** Для приера написал SQLException. Мой код бросает другой checked exception. */
    public static List<File> getNestedElements(File file) throws SQLException {
        return asList(file.listFiles());
    }
}

FunctionThr.java
Код: java
1.
2.
3.
4.
5.
package simpleexample.util;

public interface FunctionThr<S, R, H extends Throwable> {
    R apply(S src) throws H;
}

NestedDataHandler.java
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
package simpleexample.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;

public class NestedDataHandler {
    //<editor-fold defaultstate="collapsed" desc="all">
    /**
     * @param resultsHandler Обработчик для конечных элементов (и I элементов из которых они были получены)
     * @param <SR> source and result type
     * @param <I> intermediate type
     */
    public static <SR, I, H extends Throwable> void handleNestedData_all(
            SR sourceRoot,
            FunctionThr<SR, ? extends Collection<I>, H> provider,
            Function<I, SR> mapper,
            Predicate<SR> needCallProvider,
            BiConsumer<SR, I> resultsHandler
    ) throws H {
        ArrayList<I>
                listActive        = new ArrayList<>(100),
                listToHandleLater = new ArrayList<>(100);

        listActive.addAll(provider.apply(sourceRoot));

        do {
            for (I intermediate : listActive) {
                SR source = mapper.apply(intermediate);
                if (needCallProvider.test(source)) {
                    listToHandleLater.addAll(provider.apply(source));
                } else {
                    resultsHandler.accept(source, intermediate);
                }
            }

            listActive.clear();

            //<editor-fold defaultstate="collapsed" desc="swap listActive, listToHandleLater">
            ArrayList<I> tmpForSwap = listActive;
            listActive = listToHandleLater;
            listToHandleLater = tmpForSwap;
            //</editor-fold>

        } while (!listActive.isEmpty());
    }
    //</editor-fold>
}



stacktrace
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
An exception has occurred in the compiler (1.8.0_20). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.NullPointerException
	at com.sun.tools.javac.code.Scope.includes(Scope.java:296)
	at com.sun.tools.javac.comp.Flow$1.trackable(Flow.java:247)
	at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.visitVarDef(Flow.java:1832)
	at com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitVarDef(Flow.java:2569)
	at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
	at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
	at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scan(Flow.java:1376)
	at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.visitLambda(Flow.java:2256)
	at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
	at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
	at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scan(Flow.java:1376)
	at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scanExpr(Flow.java:1627)
	at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scanExprs(Flow.java:1639)
	at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.visitApply(Flow.java:2236)
	at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
	at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
	at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scan(Flow.java:1376)
	at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.analyzeTree(Flow.java:2423)
	at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.analyzeTree(Flow.java:2406)
	at com.sun.tools.javac.comp.Flow.analyzeLambdaThrownTypes(Flow.java:250)
	at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2423)
	at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
	at com.sun.tools.javac.comp.DeferredAttr$2.complete(DeferredAttr.java:284)
	at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:245)
	at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:232)
	at com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:993)
	at com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:826)
	at com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:731)
	at com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:835)
	at com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:162)
	at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:564)
	at com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:601)
	at com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3809)
	at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3615)
	at com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3522)
	at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3501)
	at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3488)
	at com.sun.tools.javac.comp.Attr.visitIdent(Attr.java:3237)
	at com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2011)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
	at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1843)
	at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
	at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:656)
	at com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1611)
	at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
	at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
	at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
	at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1035)
	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
	at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4342)
	at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4252)
	at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4181)
	at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4156)
	at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
	at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
	at com.sun.tools.javac.main.Main.compile(Main.java:523)
	at com.sun.tools.javac.main.Main.compile(Main.java:381)
	at com.sun.tools.javac.main.Main.compile(Main.java:370)
	at com.sun.tools.javac.main.Main.compile(Main.java:361)
	at com.sun.tools.javac.Main.compile(Main.java:56)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:56)
	at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1159)
	at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:935)
	at org.netbeans.modules.java.source.ant.JavacTask.execute(JavacTask.java:145)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
	at sun.reflect.GeneratedMethodAccessor465.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
	at sun.reflect.GeneratedMethodAccessor465.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
	at sun.reflect.GeneratedMethodAccessor465.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.Target.execute(Target.java:435)
	at org.apache.tools.ant.Target.performTasks(Target.java:456)
	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
	at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
	at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
	at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:286)
	at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:555)
	at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)



Кто виноват, что делать? Может кому-нибудь не лень в Oracle засабмитить баг (мне лень, да и некогда на самом деле).
...
Рейтинг: 0 / 0
Вылетает компилятор с NPE (java 8, на &#955;'ах (on lambdas))
    #38768714
Фотография Blazkowicz
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
...
Рейтинг: 0 / 0
Вылетает компилятор с NPE (java 8, на &#955;'ах (on lambdas))
    #38768717
avp.mk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Действительно, сформулированный вопрос - половина ответа))

Решение:
Явно указать сигнатуру интерфейса.
Или создать анонимный класс (что есть то же явное указание сигнатуры).

Main.java
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
package simpleexample;

import java.io.File;
import java.sql.SQLException;
import java.util.List;
import simpleexample.util.FunctionThr;

import static java.lang.System.out;
import static java.util.Arrays.asList;
import static simpleexample.util.NestedDataHandler.handleNestedData_all;

public class Main {

    public static void main(String[] args) throws SQLException {
        File rootDir = new File(".");

        handleNestedData_all(rootDir,
//                (FunctionThr<File, List<File>, SQLException>) Main::getNestedElements,              //так
//                (FunctionThr<File, List<File>, SQLException>) (File dir) -> getNestedElements(dir), //и вот так тоже можно
                (FunctionThr<File, List<File>, SQLException>) dir -> getNestedElements(dir),

                e -> e,
                File::isDirectory,
                (s, i) -> out.println(s)
        );
    }

    /** Для приера написал SQLException. Мой код бросает другой checked exception. */
    public static List<File> getNestedElements(File file) throws SQLException {
        return asList(file.listFiles());
    }
}



Но, имхо, баг всё-же есть.
...
Рейтинг: 0 / 0
Вылетает компилятор с NPE (java 8, на &#955;'ах (on lambdas))
    #38768723
Фотография Blazkowicz
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Чет там вообще не ладно в Оракле
Одно исправили
http://bugs.java.com/view_bug.do?bug_id=8042741
Другое сломали
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Вылетает компилятор с NPE (java 8, на &#955;'ах (on lambdas))
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]