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

时间:2014-06-04 01:36:49

标签: java applet illegalargumentexception

我正在尝试在网页上嵌入applet。我已将代码导出为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$6.run(HttpURLConnection.java:987)
    at sun.net.www.protocol.http.HttpURLConnection$6.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.access$300(HttpURLConnection.java:90)
    at sun.net.www.protocol.http.HttpURLConnection$12.run(HttpURLConnection.java:2565)
    at sun.net.www.protocol.http.HttpURLConnection$12.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.access$200(HttpURLConnection.java:90)
    at sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1431)
    at sun.net.www.protocol.http.HttpURLConnection$9.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$000(Unknown Source)
    at sun.plugin.PluginURLJarFileCallBack$1.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.access$1000(Unknown Source)
    at com.sun.deploy.security.DeployURLClassPath$JarLoader$1.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$3.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$2.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

我认为错误是由于尝试使用getImage()类中的Applet方法获取图像而导致的。这是代码:

try {
    image = new ImageIcon(main.getImage(main.getCodeBase(), imageName + ".png"));
} catch (Exception e) {
    e.printStackTrace();
}

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

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

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

谢谢!

4 个答案:

答案 0 :(得分:7)

如果你正在使用Java 8,那么看起来就是这个确切行为的公开错误:

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

从本质上讲,错误是它是Java中的核心错误,你无能为力。因此,您必须等待Java 8u40(如果修复程序实际上达到了目标版本)。

答案 1 :(得分:1)

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

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

我找到了一个可能的(希望是暂时的)解决方法,为那些不能等待下一个月(或4月?)的java 8u40的人提供:

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

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

如果您认为我所做的事情是非常错误的(我认为我已经删除了非必要部分),我愿意接受建议。

答案 2 :(得分:1)

运行Windows 7我遇到了JRE 8u25和8u40的问题。我回滚到7u71,上传工作正常。希望这会有所帮助。

答案 3 :(得分:0)

看起来这些调用之一(或您的主要调用)导致加载URL(看起来像是一个jar文件),然后是重定向,并且有一个空间或其中一个响应HTTP标头名称中的选项卡。如果你在本地网络服务器而不是Github上托管applet jar / war会发生什么?