-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Jsr223 fixes and updates #3576
Jsr223 fixes and updates #3576
Changes from all commits
11d3c4d
07a46ad
2f697f3
b88e5c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,20 @@ public String format(String pattern) { | |
return String.format(pattern, this.toString()); | ||
} | ||
|
||
/** | ||
* Returns the enum constant with the specified name. | ||
*/ | ||
public static UnDefType parse(String name) { | ||
if (name == null) { | ||
throw new NullPointerException("Name is null"); | ||
} | ||
if (UNDEF.toString().equals(name)) { | ||
return UNDEF; | ||
} else if (NULL.toString().equals(name)) { | ||
return NULL; | ||
} | ||
throw new IllegalArgumentException("No enum constant " | ||
+ UnDefType.class.getCanonicalName() + "." + name); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not Also, what is the likely impact of this core change? Could you separate out the UnDefType-related changes since they are wider in scope than Jsr223? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't override the valueOf method in an enum:
Try it:
The TypeParser never worked with the UnDefType I found this problem while i wrote a jsr223 script, i wanted to update a item:
i got the IllegalArgumentException and searched the reason There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is a case where a core type's
happen in the Jsr223 code? Is the script language just unable to reference Java enums using that syntax? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a general bug, i am surprised that this did not pop up earlier. I can implement a workaround especially for jsr223, but i think the TypeParser is the correct place and fixes it globally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes i know, postUpdate(ITEM, UnDefType.UNDEF) works as expected.
The TypeParser uses foreach for the getAcceptedDataTypes list. foreach uses the iterator from the ArrayList which returns the entries in proper sequence. In the StringItem, StringType is the first acceptedDataType which always match first. In each Item, the UnDefType is the last acceptedDataType, except the RollershutterItem. But this item works too, because it's values never matches the string NULL or Undefined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I suppose I'm not clear then about the JSR223 problem being solved with this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is solved, i am currently writing some JSR223 scripts and with this changes it works as expected for some days now without any issues so far. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's great, but the specific problem the change is intended to fix is still not clear to me. I have many JSR223/Jython scripts and they work as expected even without this change. I agree with @watou that this should be broken out into a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am using JavaScript an run into this issue. OK, then close this PR and i can create two separate |
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please see comment on
UnDefType