我们收到了这个错误
java.lang.NullPointerException
at java.util.ArrayList.<init>(Unknown Source)
at de.mystuff.ExtendedArrayList.<init>(ExtendedArrayList.java:38)
Run Code Online (Sandbox Code Playgroud)
其中ExtendedArrayList:38是
new ArrayList(new ArrayCollection<E>(data));
Run Code Online (Sandbox Code Playgroud)
简而言之:ArrayList构造函数有时似乎会阻塞我们自己开发的Collection实现ArrayCollection.
即使使用与我们的客户分发的完全相同的版本,我也无法在我的计算机上重现它.
但我并非100%确定他们正在使用我们所包含的JRE.所以,我搜索了一些ArrayList.java源代码,发现openJDK 6b17有这个
public ArrayList(Collection<? extends E> c) {
elementData = c.toArray();
size = elementData.length;
// c.toArray might (incorrectly) not return Object[] (see 6260652)
if (elementData.getClass() != Object[].class)
elementData = Arrays.copyOf(elementData, size, Object[].class);
}
Run Code Online (Sandbox Code Playgroud)
这是有道理的,因为如果没有数据我们的ArrayCollection.toArray()返回null.对于我们正在使用的1.5.0_09 Sun JDK/JRE实现,这个构造函数看起来很安全(并且毫无例外地工作).
但openJDK似乎只为unix世界发布.此代码是否也是Windows JRE的一部分?如果是这样,哪个版本?
注意:我知道我们必须修复我们的类,但我想确保我理解NullPointerException的原因.
我使用ubuntu 10.04和open-jdk-1.6.0.
这是我的mvn -version输出:
Apache Maven 2.2.1 (rdebian-1)
Java version: 1.6.0_20
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-37-generic" arch: "i386" Family: "unix"
Run Code Online (Sandbox Code Playgroud)
但是当我运行mvn test时,有一些错误:
/home/unionx/workspace/java/try-netty/src/test/java/net/bluedash/trynetty/DataTypeTest.java:[3,7] static import declarations are not supported in -source 1.3
(use -source 5 or higher to enable static import declarations)
import static org.junit.Assert.assertEquals;
/home/unionx/workspace/java/try-netty/src/test/java/net/bluedash/trynetty/DataTypeTest.java:[11,2] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@Test
/home/unionx/workspace/java/try-netty/src/test/java/net/bluedash/trynetty/ChannelBufferTest.java:[3,7] static import declarations are not …Run Code Online (Sandbox Code Playgroud) 我正在查看JDK 7的源代码 - 特别是WeakHashMap.java,其中有大量使用:
Entry<K,V> p = prev;
Entry<K,V> next = p.next;
Run Code Online (Sandbox Code Playgroud)
但接下来不是Map.Entry上定义的方法(据我所见?http://docs.oracle.com/javase/7/docs/api/java/util/Map.Entry.html)
从那时起对这种方法的调用在哪里?
我有一个Java 8应用程序在连接ldaps或https服务器时引发以下异常:
Caused by: javax.net.ssl.SSLHandshakeException:
Unsupported curve: 1.2.840.10045.3.1.7
Run Code Online (Sandbox Code Playgroud)
我的客户环境是:
Alpine Linux 3.5 on a Docker container
OpenJDK 1.8.0_111
Wildfly 10.1.0.Final
Run Code Online (Sandbox Code Playgroud)
如果我从以下位置连接,我可以解决此问题:
但如果我从以下地方连接,将永远失败:
是否有建议在我的Alpine Linux安装上解决此问题?
CentOs 5.4,OpenJDK运行时环境(版本1.6.0-b09)
MathContext context = new MathContext(2, RoundingMode.FLOOR);
BigDecimal total = new BigDecimal("200.0", context);
BigDecimal goodPrice = total.divide(BigDecimal.valueOf(3), 2, RoundingMode.FLOOR);
System.out.println("divided price=" + goodPrice.toPlainString());
// prints 66.66
BigDecimal goodPrice2 = total.divide(BigDecimal.valueOf(3), new MathContext(2, RoundingMode.FLOOR));
System.out.println("divided price2=" + goodPrice2.toPlainString());
// prints 66
Run Code Online (Sandbox Code Playgroud)
BUG?
尝试搜索修复程序找不到一个!我正在运行fedora 17:
Eclipse(juno)版本
eclipse-platform.x86_64 1:4.2.1-2.fc17
Run Code Online (Sandbox Code Playgroud)
一个which java收益率
/usr/bin/java
Run Code Online (Sandbox Code Playgroud)
所以eclipse正在使用正确的.
一个java -version收益率
java version "1.7.0_09-icedtea"
OpenJDK Runtime Environment (fedora-2.3.3.2.fc17-x86_64)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)
在Eclipse中/安装页说:
一个Java JRE 6/JDK推荐的Eclipse 4.2.
我需要降级吗?
我见过这个问题:
但我的配置似乎是正确的.
有任何想法吗?
目录eclipse.ini(路径/etc/eclipse.ini):
-preventMasterEclipseLaunch
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20120522-1813
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-Xms128m
-Xmx512m
-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=//usr/share/eclipse/dropins
-Dorg.eclipse.swt.browser.UseWebKitGTK=true
-Dhelp.lucene.tokenizer=standard
-XX:CompileCommand=exclude,org/eclipse/core/internal/dtree/DataTreeNode,forwardDeltaWith
-XX:CompileCommand=exclude,org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding,
-XX:CompileCommand=exclude,org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates,instantiateTemplate
-XX:CompileCommand=exclude,org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage,addBinding
-XX:CompileCommand=exclude,org/python/pydev/editor/codecompletion/revisited/PythonPathHelper,isValidSourceFile
-XX:CompileCommand=exclude,org/python/pydev/ui/filetypes/FileTypesPreferencesPage,getDottedValidSourceFiles
这是完整的错误消息
JVM terminated. Exit code=14
/usr/bin/java
-Xms128m
-Xmx512m
-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=//usr/share/eclipse/dropins
-Dorg.eclipse.swt.browser.UseWebKitGTK=true …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
import java.util.*;
public class hello {
public static void main( String[] args ) {
Collection c = new ArrayList< Integer >();
List l = new ArrayList< String >();
}
}
Run Code Online (Sandbox Code Playgroud)
并在"列表l"行中获取错误:
hello.java:6: error: incompatible types
List l = new ArrayList< String >();
^
required: List
found: ArrayList<String>
1 error
Run Code Online (Sandbox Code Playgroud)
我正在使用OpenJDK 1.7:
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.12) (7u25-2.3.12-4ubuntu3)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
Run Code Online (Sandbox Code Playgroud)
编辑:当我使用List<String>时:
hello.java:6: error: type List does not take …Run Code Online (Sandbox Code Playgroud) 我是Linux的新手,我需要在AWS的机器上安装openjdk 1.8.0_20-b26(特定版本).如果你能给出一些提示,我将不胜感激,因为它似乎yum总是安装最新的一个,并试图使用--showduplicates产量.
我将感激你的帮助.
如果我运行以下代码:
"testx".split("x")
Run Code Online (Sandbox Code Playgroud)
期望我们会得到{"test", ""},但 java 正在返回{"test"}
但"xtest".split("x")返回{"", "test"}。任何想法为什么它的行为很奇怪(或)我有错误的理解吗?
这是我的 JDK 和系统信息:
JRE:1.8.0_152-release-1024-b6 amd64
JVM:JetBrains sro 的 OpenJDK 64 位服务器 VM
Linux 4.4.0-34-generic