简体   繁体   English

使用JSR223调用重载静态方法时发生异常

[英]Exception when calling overloaded static method using JSR223

I'm trying to implement a rule for openHAB ( http://www.openhab.org/ ) in Javascript using JSR223 ( https://github.com/openhab/openhab/wiki/Jsr223-Script-Engine ). 我正在尝试使用JSR223( https://github.com/openhab/openhab/wiki/Jsr223-Script-Engine )在Javascript中实现openHAB( http://www.openhab.org/ )的规则。

Anyone having a suggestion of the root cause of following exception? 是否有人提出以下异常的根本原因? Remark that both instances passed as argument implement the interfaces used as parameters in the method declaration. 请注意,作为参数传递的两个实例都实现了在方法声明中用作参数的接口。

java.lang.RuntimeException: java.lang.NoSuchMethodException: None of the fixed arity signatures [(org.openhab.core.items.Item, org.joda.time.base.AbstractInstant)] of method org.openhab.core.persistence.extensions.PersistenceExtensions.changedSince match the argument types [org.openhab.core.items.GroupItem, org.joda.time.DateTime]
        at jdk.nashorn.javaadapters.java.util.function.Consumer.accept(Unknown Source) ~[na:na]
        at java.util.ArrayList.forEach(ArrayList.java:1249) ~[na:1.8.0_31]
        at jdk.nashorn.internal.scripts.Script$\^eval\_.L:13(<eval>:14) ~[na:na]
        at org.openhab.core.jsr223.internal.shared.Rule$$NashornJavaAdapter.execute(Unknown Source) ~[na:na]
        at org.openhab.core.jsr223.internal.engine.RuleExecutionRunnable.run(RuleExecutionRunnable.java:36) ~[na:na]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]

Following is the implemented script: 以下是已实现的脚本:

'use strict';

load("nashorn:mozilla_compat.js");
importPackage(org.openhab.core.jsr223.internal.shared);
importPackage(org.joda.time);
importPackage(org.joda.time.base);


var autoOffRule = new org.openhab.core.jsr223.internal.shared.Rule() {
    getEventTrigger: function() {
        return [
            new org.openhab.core.jsr223.internal.shared.TimerTrigger("* * * * * ?")
        ];
    }, 
    execute: function(event) {
        for each(var item in ItemRegistry.getItems()) {
            if (item.getState() == org.openhab.core.library.types.OnOffType.ON) {
                var dateTime = org.joda.time.DateTime.now().withFieldAdded(DurationFieldType.seconds(), -5);

                if (!(org.openhab.core.persistence.extensions.PersistenceExtensions.class.static.changedSince(item, var dateTime))) {
                    print("Auto-off for " + item.getName())
                }
            }            
        }
    }
};

function getRules() {
    return new org.openhab.core.jsr223.internal.shared.RuleSet([ autoOffRule ]);
}

The called method is overloaded and has following signatures: 被调用的方法已重载,并且具有以下签名:

org.openhab.core.persistence.extensions.PersistenceExtensions#changedSince(org.openhab.core.items.Item, org.joda.time.base.AbstractInstant)
org.openhab.core.persistence.extensions.PersistenceExtensions#changedSince(org.openhab.core.items.Item, org.joda.time.base.AbstractInstant, java.lang.String)

Tested and failing both on jdk1.8.0_31 and jdk1.8.0_65. 已在jdk1.8.0_31和jdk1.8.0_65上测试并均失败。 Bumped into a more or less a similar exception having a rule implemented in Groovy. 在Groovy中实现了与规则差不多的异常。

I know that I'm a necromantic when answering this question but I stumbled upon it and couldn't resist. 我知道我在回答这个问题时是个坏人,但我偶然发现了它,无法抗拒。

The error message is clear: You try to invoke the Java Method org.openhab.core.persistence.extensions.PersistenceExtensions.changedSince(org.openhab.core.items.Item, org.joda.time.DateTime) with a GroupItem . 该错误信息是明确的:您尝试调用的Java方法org.openhab.core.persistence.extensions.PersistenceExtensions.changedSince(org.openhab.core.items.Item, org.joda.time.DateTime)GroupItem

Which is interesting since a GroupItem extends the GenericItem which implements the Item Interface and therefore should match the method signature. 这很有趣,因为GroupItem扩展了实现Item接口的GenericItem因此应该与方法签名匹配。

With for each(var item in ItemRegistry.getItems()) { you get all items from your OpenHab Item Definition including all groups. for each(var item in ItemRegistry.getItems()) {您将从OpenHab项定义中获取所有项,包括所有组。 You probably only want the real items. 您可能只想要真实的物品。 Try if (! item.members ) to filter all groups. 尝试if (! item.members )过滤所有组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用JSR223断言写入文件 - Write to a file using JSR223 Assertion JMeter-在JSR223 / BeanShell采样器中调用HTTP采样器 - JMeter - Calling HTTP samplers in JSR223/BeanShell samplers 使用jsr223将JavaScript函数添加到jMeter - Adding javascript function to jMeter using jsr223 如何使用 JSR223 PreProcessor 使用 jmeter 捕获 cookie 值? - How to capture cookie value using JSR223 PreProcessor using jmeter? 使用 Jmeter 设置规则自定义 JSR223 断言和验证响应 - set rule custom JSR223 Assertion and validate response using Jmeter 如何使用JSR-223访问导致ScriptException的Java异常 - How to access Java exception that causes ScriptException using JSR-223 JMeter Javascript 语言不适用于 JSR223 Sampler 和 WebDriver Sampler - JMeter Javascript language not available for JSR223 Sampler and WebDriver Sampler 在使用 JMeter 工具进行性能测试期间 - 无法在 JSR223 和 hybrid-crypto.js 中使用 javascript 加密输入值 - During performance testing using JMeter Tool - Not able to encrypt the input values using javascript in JSR223 and hybrid-crypto.js JSR223 Javascript中的回调,Oracle JRE 1.6和OpenJDK 1.6之间的区别(比如安装在Debian上) - Callbacks in JSR223 Javascript, difference between Oracle JRE 1.6 and OpenJDK 1.6 (as installed on, say, Debian) Java脚本(jsr223):是否可以(重新)添加rhino编译功能 - Java Scripting (jsr223): is it possible to (re)add the rhino compile feature
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM