有很多问题让人们意识到用一个表达式来计算一个null值来创建一个方法引用会产生一个NullPointerException.举个例子:
String s = null;
Supplier<char[]> fun = s::toCharArray;
Run Code Online (Sandbox Code Playgroud)
这是由于java规范中的以下段落:
首先,如果方法引用表达式以ExpressionName或Primary开头,则计算此子表达式.如果子表达式的计算结果为null,则会引发NullPointerException,并且方法引用表达式会突然完成.如果子表达式突然完成,则方法引用表达式会出于同样的原因突然完成.
现在我的问题是,有没有人碰巧知道背后的原因(基于许多困惑的问题)反直觉规范是什么?
我唯一想到的是,在以下情况下,很难准确地报告NullPointerException在评估期间发生的错误Supplier:
public static char[] callback(Supplier<char[]> supplier) {
return supplier.get();
}
public static void main(String[] args) {
String s = null;
callback(s::toCharArray);
}
Run Code Online (Sandbox Code Playgroud) 我使用org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder以下面的方式构建REST客户端:
ResteasyClient client = (new ResteasyClientBuilder())
.maxPooledPerRoute(5)
.connectionPoolSize(10)
.socketTimeout(10L, TimeUnit.SECONDS)
.register(jacksonProvider)
.register(new RestClientLogger())
.register(new RestClientMDCFilter())
.build();
Run Code Online (Sandbox Code Playgroud)
在jacksonProvider那里注册的是一个ResteasyJackson2Provider jacksonProvider = new ResteasyJackson2Provider();带有ObjectMapper对反序列化很重要的自定义.到目前为止,问题是,我在JBoss中得到以下警告:
10:31:38,414 WARN [org.jboss.resteasy.resteasy_jaxrs.i18n] (default-threads - 1) RESTEASY002155: Provider class org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider is already registered. 2nd registration is being ignored.
Run Code Online (Sandbox Code Playgroud)
如果在已经存在之前已注册的同一类的实例的情况下检查文档,这是有意义的.我使用反编译器来检查ResteasyClientBuilder正在做什么并且能够看到,它扫描类路径以查找包含描述应该注册"内置"提供程序的资源的jar.
其中一个jboss提供的实现现在显然已经定义了一个ResteasyJackson2Provider在那里注册的实现,这使我以后无法注册我自己的实例.
我有什么选择?我需要得到我的版本ResteasyJackson2Provider- 或者至少是我的版本ObjectMapper.我可以以某种方式取代现有的吗?
我目前正在尝试编写一个通过Maven运行的测试,该测试专门针对包含UTF-8字符的字符串。如果我在IntelliJ中运行所说的测试,一切都很好,并且结果符合预期。如果我使用mvn test运行测试,则(仅)正在测试UTF-8字符的测试失败。
这是我的测试:
@Test
public void testWithUTF8() throws InvalidKeyException, NoSuchAlgorithmException {
String signature = NFLAuth.sign("Contains UTF-8: äüöööÕßÍÑð");
Assert.assertEquals("Signature=BSY4prbinpAgzJLv6ffGm+XJb1NTIbGY6gTj8RA3lsA=", signature);
}
Run Code Online (Sandbox Code Playgroud)
首先,是的,我阅读了有关在Maven中进行编码的问题,然后我做了一切。Theres属性,将其添加到编译器插件中,我什至用file.encoding设置了JAVA_TOOL_OPTIONS,但还是没有运气。我还不知道它使用的是什么编码,如果我在IntelliJ中尝试Windows-1252,则测试也会失败,但是签名与maven获得的签名不同。
这是POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>***</groupId>
<artifactId>***</artifactId>
<version>1.0</version>
<name>***</name>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency> …Run Code Online (Sandbox Code Playgroud) 我有以下 - 简化 - 表格布局:
content.blockId是 的外键blocks.id。这个想法是,在内容表中,对于一个块,您有许多不同类型的内容条目。
我现在正在寻找一个查询,它可以为我提供基于 blockId 的聚合,其中 3 种不同类型的所有内容条目都连接起来并放入相应的列中。
我已经开始并找到了listagg运行良好的函数,我做了以下语句并在列中列出了所有内容条目:
SELECT listagg(c.data, ',') WITHIN GROUP (ORDER BY c.order) FROM content c WHERE c.blockId = 330;
Run Code Online (Sandbox Code Playgroud)
然而,现在连接的字符串data在一列中包含块的所有元素。我想实现的是根据类型将其放入单独的列中。例如下面的内容content是这样的:
现在我想输出 2 列,一个是 FRAGMENT,一个是 BULK,其中 FRAGMENT 包含“content1;content3;content4”,BULK 包含“content2”
有没有一种有效的方法来实现这一目标?
我正在尝试使用Kafka Streams,并且创建了以下拓扑:
KStream<String, HistoryEvent> eventStream = builder.stream(applicationTopicName, Consumed.with(Serdes.String(),
historyEventSerde));
eventStream.selectKey((key, value) -> new HistoryEventKey(key, value.getIdentifier()))
.groupByKey()
.reduce((e1, e2) -> e2, Materialized.as(streamByKeyStoreName));
Run Code Online (Sandbox Code Playgroud)
稍后,我像这样启动流:
private void startKafkaStreams(KafkaStreams streams) {
CompletableFuture<KafkaStreams.State> stateFuture = new CompletableFuture<>();
streams.setStateListener((newState, oldState) -> {
if(stateFuture.isDone()) {
return;
}
if(newState == KafkaStreams.State.RUNNING || newState == KafkaStreams.State.ERROR) {
stateFuture.complete(newState);
}
});
streams.start();
try {
KafkaStreams.State finalState = stateFuture.get();
if(finalState != KafkaStreams.State.RUNNING) {
// ...
}
} catch (InterruptedException ex) {
// ...
} catch(ExecutionException ex) {
// ...
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个包含以下行的 Dockerfile:
ENTRYPOINT ["java", "-Dconversion.rules.folder=/var/rules", "-jar", "/var/gateway-service-${project.version}.jar"]
我正在配置maven-resources-plugin如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-docker-artifacts</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>package</phase>
<configuration>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<includes>
<include>${project.artifactId}.tar</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/src/main/docker</directory>
<filtering>true</filtering>
</resource>
</resources>
<outputDirectory>${project.build.directory}/docker</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我期待着project.version被替换。由于某种原因,这不是真的。然后我使用调试模式运行构建,它输出以下内容:
[INFO] Copying 1 resource
[DEBUG] Copying file Dockerfile
[DEBUG] file Dockerfile has a filtered file extension
[DEBUG] filtering ...\src\main\docker\Dockerfile to ...\target\docker\Dockerfile
[DEBUG] no use filter components
Run Code Online (Sandbox Code Playgroud)
在我看来,过滤应该有效,但是中的文件target仍然包含${project.version}. 我在这里缺少什么?
我还尝试将其他非 Dockerfile 文件放入 Dockerfile 所在的同一文件夹中,但是那里也没有应用过滤...