我安装了新的JDK 1.8版本:40现在我正在从一个有效的javascript函数中跟踪异常间歇性,有什么想法?
java version "1.8.0_40-ea"
Java(TM) SE Runtime Environment (build 1.8.0_40-ea-b19)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b23, mixed mode)
例外:
.....
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.script.ScriptException: TypeError: function __noSuchMethod__() { [native code] } is not a constructor function in <eval> at line number 21
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:455)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:439)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:401)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:397)
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:152)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at com.nube.portal.engines.js.JsEngine.eval(JsEngine.java:101)
... 74 more
Caused by: <eval>:21 TypeError: function __noSuchMethod__() { [native code] } is not a constructor function
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:213)
at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:185)
at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:172)
at jdk.nashorn.internal.runtime.ScriptFunctionData.getBestConstructor(ScriptFunctionData.java:239)
at jdk.nashorn.internal.runtime.ScriptFunction.findNewMethod(ScriptFunction.java:474)
at jdk.nashorn.internal.runtime.ScriptObject.lookup(ScriptObject.java:1874)
at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:100)
at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:94)
at jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:176)
at jdk.internal.dynalink.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:124)
at jdk.internal.dynalink.support.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:149)
at jdk.internal.dynalink.DynamicLinker.relink(DynamicLinker.java:233)
at jdk.nashorn.internal.scripts.Script$Recompilation$9$134AAA$\^eval\_.L:6$http(<eval>:21)
at jdk.nashorn.internal.scripts.Script$Recompilation$8$977AA$\^eval\_.L:6$get(<eval>:41)
at jdk.nashorn.internal.scripts.Script$7$\^eval\_.:program(<eval>:1)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:636)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:437)
... 79 more
代码:此实用程序将有助于拨打休息服务。
(function (global, factory) {
factory(global.Rest = {});
}(this, function (rest) {
rest.http = function(url, request, method) {
method = (method == null?"GET":method);
if(request != undefined){
for (var key in request) {
if (request.hasOwnProperty(key)) {
url = url + key+"="+request[key] +"&";
}
}
}
with (new JavaImporter(java.io, java.net)) {
var is = new URL(url).openConnection();
try {
is.setRequestProperty("Content-Type", "application/json");
is.setRequestMethod(method);
var reader = new BufferedReader(
new InputStreamReader(is.getInputStream()));
var buf = '', line = null;
while ((line = reader.readLine()) != null) {
buf += line;
}
} finally {
reader.close();
}
return buf;
}
};
rest.get = function(url, request){
return JSON.parse(rest.http(url, request, "GET"));
};
}));
现在我正在使用Rest.get()进行服务调用
var result = Rest.get("http://someurl?...");
此调用可以正常运行,并在一段时间后开始抛出异常。
答案 0 :(得分:2)
我遇到了同样的问题。
可能,这是JavaImporter的错误。
我没有使用JavaImpoter解决了这个问题。
答案 1 :(得分:0)
我用下面的代码摆脱了这个异常:
class Human(models.Model):
SHIRT_SIZES = (('XXS', 'XXS'), ('XS', 'XS'), ('S', 'S'), ('M', 'M'), ('L', 'L'), ('XL', 'XL'), ('XXL', 'XXL'))
team = models.ForeignKey(Team, on_delete=models.CASCADE)
first_name = models.CharField(max_length=16)
last_name = models.CharField(max_length=16)
jersey_size = models.CharField(max_length=4, choices=SHIRT_SIZES, blank=True)
slug = models.SlugField(blank=True)
def save(self, *args, **kwargs):
self.slug = slugify(self.first_name + ' ' + self.last_name)
super(Human, self).save(*args, **kwargs)
def __str__(self):
return self.first_name + ' ' + self.last_name
class Player(Human):
year_of_birth = models.IntegerField(validators=[MinValueValidator(1900), MaxValueValidator(2100)], blank=True, null=True)
jersey_number = models.IntegerField(validators=[MinValueValidator(0), MaxValueValidator(99)], blank=True, null=True)
all_star_game = models.ForeignKey(AllStarGame, on_delete=models.CASCADE, blank=True, null=True)
我使用importClass代替JavaImporter。