java.lang.IllegalArgumentException:不允许使用空格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24027671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 09:46:55  来源:igfitidea点击:

java.lang.IllegalArgumentException: white space not allowed

javaappletillegalargumentexception

提问by nrubin29

I am attempting to embed an applet on a webpage. I have exported the code as a compressed applet in IntelliJ. Now, when I try to run it, I get the following stack trace:

我试图在网页上嵌入一个小程序。我已将代码导出为 IntelliJ 中的压缩小程序。现在,当我尝试运行它时,我得到以下堆栈跟踪:

java.lang.IllegalArgumentException: white space not allowed
    at java.net.URLPermission.normalizeHeaders(URLPermission.java:401)
    at java.net.URLPermission.init(URLPermission.java:189)
    at java.net.URLPermission.<init>(URLPermission.java:166)
    at sun.net.www.protocol.http.HttpURLConnection.URLtoSocketPermission(HttpURLConnection.java:1031)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1424)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at com.sun.deploy.net.HttpUtils.followRedirects(Unknown Source)
    at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
    at com.sun.deploy.net.BasicHttpRequest.doGetRequestEX(Unknown Source)
    at com.sun.deploy.cache.ResourceProviderImpl.checkUpdateAvailable(Unknown Source)
    at com.sun.deploy.cache.ResourceProviderImpl.isUpdateAvailable(Unknown Source)
    at com.sun.deploy.cache.DeployCacheHandler.get(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1048)
    at sun.net.www.protocol.http.HttpURLConnection.run(HttpURLConnection.java:987)
    at sun.net.www.protocol.http.HttpURLConnection.run(HttpURLConnection.java:985)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessController.doPrivileged(AccessController.java:713)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:984)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
    at sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2648)
    at sun.net.www.protocol.http.HttpURLConnection.access0(HttpURLConnection.java:90)
    at sun.net.www.protocol.http.HttpURLConnection.run(HttpURLConnection.java:2565)
    at sun.net.www.protocol.http.HttpURLConnection.run(HttpURLConnection.java:2563)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessController.doPrivileged(AccessController.java:713)
    at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2562)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1768)
    at sun.net.www.protocol.http.HttpURLConnection.access0(HttpURLConnection.java:90)
    at sun.net.www.protocol.http.HttpURLConnection.run(HttpURLConnection.java:1431)
    at sun.net.www.protocol.http.HttpURLConnection.run(HttpURLConnection.java:1429)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessController.doPrivileged(AccessController.java:713)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1428)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at sun.plugin.PluginURLJarFileCallBack.downloadJAR(Unknown Source)
    at sun.plugin.PluginURLJarFileCallBack.access
try {
    image = new ImageIcon(main.getImage(main.getCodeBase(), imageName + ".png"));
} catch (Exception e) {
    e.printStackTrace();
}
0(Unknown Source) at sun.plugin.PluginURLJarFileCallBack.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.plugin.PluginURLJarFileCallBack.retrieve(Unknown Source) at sun.net.www.protocol.jar.URLJarFile.retrieve(URLJarFile.java:205) at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:71) at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:99) at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122) at sun.plugin.net.protocol.jar.CachedJarURLConnection.connect(Unknown Source) at sun.plugin.net.protocol.jar.CachedJarURLConnection.getJarFileInternal(Unknown Source) at sun.plugin.net.protocol.jar.CachedJarURLConnection.getJarFile(Unknown Source) at com.sun.deploy.security.DeployURLClassPath$JarLoader.getJarFile(Unknown Source) at com.sun.deploy.security.DeployURLClassPath$JarLoader.access00(Unknown Source) at com.sun.deploy.security.DeployURLClassPath$JarLoader.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.deploy.security.DeployURLClassPath$JarLoader.ensureOpen(Unknown Source) at com.sun.deploy.security.DeployURLClassPath$JarLoader.<init>(Unknown Source) at com.sun.deploy.security.DeployURLClassPath.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.deploy.security.DeployURLClassPath.getLoader(Unknown Source) at com.sun.deploy.security.DeployURLClassPath.getLoader(Unknown Source) at com.sun.deploy.security.DeployURLClassPath.getResource(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source) at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source) at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Thread.java:744) Ignored exception: java.lang.IllegalArgumentException: white space not allowed

I believe the error was caused by trying to get an image with the getImage()method in the Appletclass. This is the code:

我相信错误是由于尝试使用类中的getImage()方法获取图像引起的Applet。这是代码:

InputStream in = new URL(myUrl).openConnection().getInputStream();

For reference, here's the tag I'm using in the HTML:

作为参考,这是我在 HTML 中使用的标签:

<applet archive="https://github.com/nrubin29/FreeFall-Applets/blob/master/Noah/Noah.war?raw=true" code="FreeFallMain"></applet>

<applet archive="https://github.com/nrubin29/FreeFall-Applets/blob/master/Noah/Noah.war?raw=true" code="FreeFallMain"></applet>

If you want to see the error for yourself, just go to http://nrubin29.github.io/FreeFall-Applets/

如果您想自己查看错误,只需转到http://nrubin29.github.io/FreeFall-Applets/

Thanks!

谢谢!

采纳答案by PsndCsrV

If you're using Java 8, it looks like there's an open bug around this exact behavior:

如果您使用的是 Java 8,那么这个确切的行为似乎存在一个未解决的错误:

https://bugs.openjdk.java.net/browse/JDK-8042622?page=com.atlassian.jira.plugin.system.issuetabpanels:changehistory-tabpanel

https://bugs.openjdk.java.net/browse/JDK-8042622?page=com.atlassian.jira.plugin.system.issuetabpanels:changehistory-tabpanel

In essence, the bug is that it's a core bug in Java, and nothing you can do can fix it. So you'll have to wait for Java 8u40 (if the fix actually hits their target release).

本质上,bug 是 Java 中的一个核心 bug,你无能为力。因此,您将不得不等待 Java 8u40(如果修复程序实际上达到了他们的目标版本)。

回答by David Ehrmann

It looks like one of those calls (or your main call) is causing a URL to be loaded (looks like it's a jar file), then there's a redirect, and there's a space or tab in one of the response HTTP headers names. What happens if you host the applet jar/war on a local webserver rather than Github?

看起来其中一个调用(或您的主调用)导致 URL 被加载(看起来它是一个 jar 文件),然后是重定向,并且响应 HTTP 标头名称之一中有一个空格或制表符。如果您在本地网络服务器而不是 Github 上托管小程序 jar/war 会发生什么?

回答by Matteo Steccolini

I had a similar issue (with the upgrade from java 1.7.0_67 to java 1.8.0_25) opening a page that redirects to a pdf document with code like this:

我有一个类似的问题(从 java 1.7.0_67 升级到 java 1.8.0_25)打开一个页面,重定向到一个 pdf 文档,代码如下:

try {
    InputStream in = new URL(myUrl).openConnection().getInputStream();
} catch (IllegalArgumentException iae) {
    in = sun.net.www.protocol.http.HttpURLConnection.openConnectionCheckRedirects(new URL(myUrl).openConnection());
}

I have found a possible (hopefully temporary) workaround for those who can't wait next january (or april?) for java 8u40:

对于那些迫不及待要等到明年 1 月(或 4 月?)Java 8u40 的人,我找到了一个可能的(希望是临时的)解决方法:

##代码##

You can obviously add log and check if the open connection is istanceof HttpURLConnection.

您显然可以添加日志并检查打开的连接是否是 HttpURLConnection 的 istanceof。

I'm open to suggestions if you think what I've done is very wrong (consider I've stripped the non-essential parts).

如果您认为我所做的非常错误,我愿意接受建议(考虑到我已经剥离了非必要部分)。

回答by user4297587

Running Windows 7 I had this issue with JRE 8u25, and also with 8u40. I rolled back to 7u71 and the uploader works fine. Hope this helps.

运行 Windows 7 我在使用 JRE 8u25 和 8u40 时遇到了这个问题。我回滚到 7u71,上传器工作正常。希望这可以帮助。