Я использую PlayFramework для создаваемого веб-сайта, и мне удалось настроить практически все (даже БД), но следующий класс, основанный на документации Play 2.8 -> https://www.playframework.com/documentation/2.8.x/AccessingAnSQLDatabase не работает
Класс:
package models;
import javax.inject.*;
import play.db.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
public class FeedRepository {
private Database db;
private DatabaseExecutionContext executionContext;
@Inject
public FeedRepository(Database db, DatabaseExecutionContext context) {
this.db = db;
this.executionContext = executionContext;
}
/*
* supplyAsync(Supplier<U> supplier) Returns a new CompletableFuture that is
* asynchronously completed by a task running in the ForkJoinPool.commonPool()
* with the value obtained by calling the given Supplier.
*/
public CompletionStage<List<FeedArticle>> getArticleList() {
return CompletableFuture.supplyAsync(() -> {
return db.withConnection(connection -> {
List<FeedArticle> list = new ArrayList<FeedArticle>();
try {
String sql = "select * from feed_pages;";
PreparedStatement statement = connection.prepareStatement(sql);
ResultSet rsd = statement.executeQuery();
while (rsd.next()) {
list.add(new FeedArticle(rsd.getString("page_title"), rsd.getString("page_url"),
rsd.getDate("page_last_check"), rsd.getString("website_domain")));
}
rsd.close();
statement.close();
} catch (Exception e) {
e.printStackTrace();
}
return list;
});
}, executionContext);
}
}
При попытке выполнить код выше я получаю сообщение об ошибке: [error] pahDefaultHttpErrorHandler -
! @7ffho3fhh - Internal server error, for (GET) [/feed-reader/articles/] ->
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[NullPointerException: null]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:335)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:253)
at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:424)
at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:420)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:453)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:92)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:92)
Caused by: java.lang.NullPointerException: null
at java.util.concurrent.CompletableFuture.screenExecutor(CompletableFuture.java:415)
at java.util.concurrent.CompletableFuture.supplyAsync(CompletableFuture.java:1843)
at models.FeedRepository.getArticleList(FeedRepository.java:33)
at controllers.FeedReaderController.feedpostslist(FeedReaderController.java:38)
at router.Routes$$anonfun$routes$1.$anonfun$applyOrElse$2(Routes.scala:94)
at play.core.routing.HandlerInvokerFactory$$anon$7.resultCall(HandlerInvoker.scala:144)
at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$3$$anon$4$$anon$5.invocation(HandlerInvoker.scala:113)
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:119)
at play.http.DefaultActionCreator$1.call(DefaultActionCreator.java:33)
at play.core.j.JavaAction.$anonfun$apply$8(JavaAction.scala:175)
Что я делаю не так?
Кажется, проблема здесь -> return CompletableFuture.supplyAsyn c (