IllegalArgumentException at URLPermission in jre8

十年热恋 提交于 2019-12-04 22:02:00

Debugin your code snippet in an applet, shows that the parameter actions passed to URLPermission, which ist new win java8, has the value GET:pragma: which is not valid according to javadoc for that argument:

The actions string of a URLPermission is a concatenation of the method list and the request headers list. These are lists of the permitted request methods and permitted request headers of the permission (respectively). The two lists are separated by a colon ':' character and elements of each list are comma separated. Some examples are:

     "POST,GET,DELETE"
     "GET:X-Foo-Request,X-Bar-Request"
     "POST,GET:Header1,Header2"

and according to the code in oracle's jdk8:

int colon = actions.indexOf(':');
if (actions.lastIndexOf(':') != colon) {
    throw new IllegalArgumentException("invalid actions string");
}

The code above expects one single colon or none.

To solve the problem you need to remove the colon after pragma in your call

con.setRequestProperty("pragma", "no-cache");

Running your snippet as simple junit test does not provoke this exception, because the URLPermition class is not invoked. Whether it invoked or not depends on the context where the application is running.

Note. Depending on the context of use, some request methods and headers may be permitted at all times, and others may not be permitted at any time. For example, the HTTP protocol handler might disallow certain headers such as Content-Length from being set by application code, regardless of whether the security policy in force, permits it.

So it seems, when in the context of an applet some permition checks are performed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!