Closed rvjansen closed 1 year ago
This affects Qtime.nrx shipped with Netrexx
we might need to backpedal on automatically include this - and some other things - in scripting mode
now after consultation of the list - is implemented to be the standard choice. Breakage can be avoided with a -noimplicituses option. (Implemented by Marc Remes and included in 4.05)
issue resolved
Ran into another problem (a NetRexx program that would use in the past). Here a stripped down version of the problem:
import java.text.SimpleDateFormat import java.util.Date
timeStamp = SimpleDateFormat("yyyy.MM.dd.HH.mm.ss.SSSSSS").format(Date()) say "timeStamp:" timeStamp The JavaDocs 8 for SimpleDateFormat (which is a subclass of DateFormat): https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html. Here the signatures of the available format methods in SimpleDateFormat and DateFormat:
StringBuffer SimpleDateFormat.format(Date date, StringBuffer toAppendTo, FieldPosition pos) String DateFormat.format(Date date) abstract DateFormat.format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) StringBuffer DateFormat.format(Object obj, StringBuffer toAppendTo, FieldPosition fieldPosition) Clearly DateFormat.format(Date date) should be picked.
Here the runtime error when interpreting:
F:\work\svn\bsf4oorexx\trunk\samples\NetRexx\javax.script>nrc -exec test2.nrx java -cp "F:\work\svn\bsf4oorexx\trunk;.;C:\Program Files\BSF4ooRexx\bsf4ooRexx-v641-20220808-bin.jar;C:\Program Files\BSF4ooRexx\jni4net .j-0.8.8.0.jar;C:\Program Files\BSF4ooRexx\oorexx.net.jar;.;E:\java\scriptJars\NetRexx\403\lib*;;E:\java\scriptJars\NetRexx\403\lib\NetR exxF.jar;." -Dnrx.compiler=ecj org.netrexx.process.NetRexxC -exec test2.nrx NetRexx portable processor 4.03-GA build 260-20220503-1730 Copyright (c) RexxLA, 2011,2022. All rights reserved. Parts Copyright (c) IBM Corporation, 1995,2008. Program test2.nrx ===== Exec: test2 ===== ===== Exception running class test2: java.lang.IllegalArgumentException: Cannot format given Object as a Date ===== --- in test2.main(String[]) [test2.nrx:5] 5 +++ timeStamp = SimpleDateFormat("yyyy.MM.dd.HH.mm.ss.SSSSSS").format(Date()) +++ ^^^^^^ Processing of 'test2.nrx' complete However, compiling that NetRexx program works:
F:\work\svn\bsf4oorexx\trunk\samples\NetRexx\javax.script>nrc test2.nrx java -cp "F:\work\svn\bsf4oorexx\trunk;.;C:\Program Files\BSF4ooRexx\bsf4ooRexx-v641-20220808-bin.jar;C:\Program Files\BSF4ooRexx\jni4net .j-0.8.8.0.jar;C:\Program Files\BSF4ooRexx\oorexx.net.jar;.;E:\java\scriptJars\NetRexx\403\lib*;;E:\java\scriptJars\NetRexx\403\lib\NetR exxF.jar;." -Dnrx.compiler=ecj org.netrexx.process.NetRexxC test2.nrx NetRexx portable processor 4.03-GA build 260-20220503-1730 Copyright (c) RexxLA, 2011,2022. All rights reserved. Parts Copyright (c) IBM Corporation, 1995,2008. Program test2.nrx Compilation of 'test2.nrx' successful Running the class file with Java creates an exception:
F:\work\svn\bsf4oorexx\trunk\samples\NetRexx\javax.script>java test2 Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date at java.text.DateFormat.format(DateFormat.java:310) at java.text.Format.format(Format.java:157) at test2.main(test2.java:6) Doing a javap -v -l on the NetRexx produced class file yields:
Classfile /F:/work/svn/bsf4oorexx/trunk/samples/NetRexx/javax.script/test2.class Last modified 08.08.2022; size 942 bytes MD5 checksum 599c340ea77ea0570397dd3540bfe73b Compiled from "test2.java" public class test2 minor version: 0 major version: 51 flags: ACC_PUBLIC, ACC_SUPER Constant pool:
1 = Class #2 // test2
2 = Utf8 test2
3 = Class #4 // java/lang/Object
4 = Utf8 java/lang/Object
5 = Utf8 $01
6 = Utf8 Lnetrexx/lang/Rexx;
7 = Utf8 $0
8 = Utf8 Ljava/lang/String;
9 = Utf8 ConstantValue
10 = String #11 // test2.nrx
11 = Utf8 test2.nrx
12 = Utf8
13 = Utf8 ()V
14 = Utf8 Code
15 = String #16 // timeStamp:
16 = Utf8 timeStamp:
17 = Methodref #18.#20 // netrexx/lang/Rexx.toRexx:(Ljava/lang/String;)Lnetrexx/lang/Rexx;
18 = Class #19 // netrexx/lang/Rexx
19 = Utf8 netrexx/lang/Rexx
20 = NameAndType #21:#22 // toRexx:(Ljava/lang/String;)Lnetrexx/lang/Rexx;
21 = Utf8 toRexx
22 = Utf8 (Ljava/lang/String;)Lnetrexx/lang/Rexx;
23 = Fieldref #1.#24 // test2.$01:Lnetrexx/lang/Rexx;
24 = NameAndType #5:#6 // $01:Lnetrexx/lang/Rexx;
25 = Utf8 LineNumberTable
26 = Utf8 main
27 = Utf8 ([Ljava/lang/String;)V
28 = Class #29 // java/text/SimpleDateFormat
29 = Utf8 java/text/SimpleDateFormat
30 = String #31 // yyyy.MM.dd.HH.mm.ss.SSSSSS
31 = Utf8 yyyy.MM.dd.HH.mm.ss.SSSSSS
32 = Methodref #28.#33 // java/text/SimpleDateFormat."":(Ljava/lang/String;)V
33 = NameAndType #34:#35 // "":(Ljava/lang/String;)V
34 = Utf8
35 = Utf8 (Ljava/lang/String;)V
36 = Methodref #37.#39 // netrexx/lang/RexxDate.Date:()Lnetrexx/lang/Rexx;
37 = Class #38 // netrexx/lang/RexxDate
38 = Utf8 netrexx/lang/RexxDate
39 = NameAndType #40:#41 // Date:()Lnetrexx/lang/Rexx;
40 = Utf8 Date
41 = Utf8 ()Lnetrexx/lang/Rexx;
42 = Methodref #28.#43 // java/text/SimpleDateFormat.format:(Ljava/lang/Object;)Ljava/lang/String;
43 = NameAndType #44:#45 // format:(Ljava/lang/Object;)Ljava/lang/String;
44 = Utf8 format
45 = Utf8 (Ljava/lang/Object;)Ljava/lang/String;
46 = Methodref #18.#47 // netrexx/lang/Rexx.OpCcblank:(Lnetrexx/lang/RexxSet;Lnetrexx/lang/Rexx;)Lnetrexx/lang/Rexx;
47 = NameAndType #48:#49 // OpCcblank:(Lnetrexx/lang/RexxSet;Lnetrexx/lang/Rexx;)Lnetrexx/lang/Rexx;
48 = Utf8 OpCcblank
49 = Utf8 (Lnetrexx/lang/RexxSet;Lnetrexx/lang/Rexx;)Lnetrexx/lang/Rexx;
50 = Methodref #51.#53 // netrexx/lang/RexxIO.Say:(Lnetrexx/lang/Rexx;)Z
51 = Class #52 // netrexx/lang/RexxIO
52 = Utf8 netrexx/lang/RexxIO
53 = NameAndType #54:#55 // Say:(Lnetrexx/lang/Rexx;)Z
54 = Utf8 Say
55 = Utf8 (Lnetrexx/lang/Rexx;)Z
56 = Methodref #3.#57 // java/lang/Object."":()V
57 = NameAndType #34:#13 // "":()V
58 = Utf8 SourceFile
59 = Utf8 test2.java
{ static {}; descriptor: ()V flags: ACC_STATIC Code: stack=1, locals=0, args_size=0 0: ldc #15 // String timeStamp: 2: invokestatic #17 // Method netrexx/lang/Rexx.toRexx:(Ljava/lang/String;)Lnetrexx/lang/Rexx; 5: putstatic #23 // Field $01:Lnetrexx/lang/Rexx; 8: return LineNumberTable: line 5: 0
public static void main(java.lang.String[]); descriptor: ([Ljava/lang/String;)V flags: ACC_PUBLIC, ACC_STATIC Code: stack=3, locals=2, args_size=1 0: new #28 // class java/text/SimpleDateFormat 3: dup 4: ldc #30 // String yyyy.MM.dd.HH.mm.ss.SSSSSS 6: invokespecial #32 // Method java/text/SimpleDateFormat."":(Ljava/lang/String;)V
9: invokestatic #36 // Method netrexx/lang/RexxDate.Date:()Lnetrexx/lang/Rexx;
12: invokevirtual #42 // Method java/text/SimpleDateFormat.format:(Ljava/lang/Object;)Ljava/lang/String;
15: astore_1
16: getstatic #23 // Field $01:Lnetrexx/lang/Rexx;
19: aconst_null
20: aload_1
21: invokestatic #17 // Method netrexx/lang/Rexx.toRexx:(Ljava/lang/String;)Lnetrexx/lang/Rexx;
24: invokevirtual #46 // Method netrexx/lang/Rexx.OpCcblank:(Lnetrexx/lang/RexxSet;Lnetrexx/lang/Rexx;)Lnetrexx/lang/Rexx;
27: invokestatic #50 // Method netrexx/lang/RexxIO.Say:(Lnetrexx/lang/Rexx;)Z
30: pop
31: return
LineNumberTable:
line 6: 0
}
SourceFile: "test2.java"
So "java.util.Date" is not in the class file, instead RexxDate gets used.
Changing the program to:
import java.text.SimpleDateFormat import java.util.Date
timeStamp = SimpleDateFormat("yyyy.MM.dd.HH.mm.ss.SSSSSS").format(java.util.Date()) say "timeStamp:" timeStamp makes it work (also running the class file with Java works then, ie. "java test2").
Again, in the past the latter "fix" was not necessary.
Also a successful compilation should not occur (using "javac 1.8.0_333" in this case) as the generated program cannot possibly run as a RexxDate cannot be casted to a java.util.Date which is needed as the argument type in the DateFormat.format(Date).
---rony