[x3d-public] X3DJSAIL, X3dToJava.xslt and DOMX3DLoaderObjecttesting:anotherClassCastException

Don Brutzman brutzman at nps.edu
Thu Jun 7 20:44:14 PDT 2018


Sorry but no, advancing a version in Java is a slippery slope if everything can't advance together.  Am holding at JDK 8 until Netbeans (and thus X3D-Edit) gets upgraded to JDK 9 or 10.

On 6/6/2018 4:07 PM, John Carlson wrote:
> Full script under OpenJDK 8,  Ubuntu on Windows 10.  Log attached.  The readAllBytes issue will be fixed by Java 9.  Is there a way to set your ant
> JDK to JDK 9 inside NetBeans?  Wondering.
> 
> John
> 
> $ cd /mnt/c/x3d-code/www.web3d.org/x3d/stylesheets/java/
> 
> $ javac -cp lib/javax.json-api-1.0.jar src/net/coderextreme/X3DJSONLD.java
> 
> $ cp src/net/coderextreme/X3DJSONLD.class classes/net/coderextreme/
> 
> # use ; instead of : in command prompt and git bash
> 
> $ jjs -J-Djava.class.path=jars/X3DJSAIL.3.3.full.jar:classes nashorn/examples/Json.js
> 
> $ diff -w nashorn/examples/HelloWorldProgramOutput.Java.x3d nashorn/examples/Json.x3d
> 
> You should be able to duplicate the error with JDK 8 this way.  Command prompt will differ slightly.
> 
> John
> 
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
> 
> *From: *John Carlson <mailto:yottzumm at gmail.com>
> *Sent: *Wednesday, June 6, 2018 6:06 PM
> *To: *Don Brutzman <mailto:brutzman at nps.edu>
> *Cc: *x3d-public at web3d.org <mailto:x3d-public at web3d.org>
> *Subject: *RE: X3DJSAIL, X3dToJava.xslt and DOMX3DLoaderObjecttesting:anotherClassCastException
> 
> Under OpenJDK 8 on Ubuntu under windows, the jjs command is:
> 
> $ jjs -J-Djava.class.path=jars/X3DJSAIL.3.3.full.jar:classes nashorn/examples/Json.js
> 
> And the cd command is:
> 
> $ cd /mnt/c/x3d-code/www.web3d.org/x3d/stylesheets/java/
> 
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
> 
> *From: *John Carlson <mailto:yottzumm at gmail.com>
> *Sent: *Wednesday, June 6, 2018 5:37 PM
> *To: *Don Brutzman <mailto:brutzman at nps.edu>
> *Cc: *x3d-public at web3d.org <mailto:x3d-public at web3d.org>
> *Subject: *RE: X3DJSAIL, X3dToJava.xslt and DOM X3DLoaderObjecttesting:anotherClassCastException
> 
> Try stepping through with these commands at command prompt or similar (you’ll have to use diff and cp from Ubuntu, now available on Windows or similar commands under DOS)
> 
> $ cd /c/x3d-code/www.web3d.org/x3d/stylesheets/java/
> 
> $ javac -cp lib/javax.json-api-1.0.jar src/net/coderextreme/X3DJSONLD.java
> 
> $ cp src/net/coderextreme/X3DJSONLD.class classes/net/coderextreme/
> 
> $ jjs -cp "jars/X3DJSAIL.3.3.full.jar;classes" nashorn/examples/Json.js    # you may have to use the Java 8 way of specifying the classpath. See build.xml
> 
> $ diff -w nashorn/examples/HelloWorldProgramOutput.Java.x3d nashorn/examples/Json.x3d
> 
> 32a33,35
> 
>  >         <meta name='translated' content='27 May 2018'/>
> 
>  >         <meta name='generator' content='X3dToJson.xslt, http://www.web3d.org/x3d/stylesheets/X3dToJson.html'/>
> 
>  >         <meta name='reference' content='X3D JSON encoding: http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding'/>
> 
> 35,38c38
> 
> <         <ViewpointGroup description='Available viewpoints'>
> 
> <             <Viewpoint DEF='DefaultView' description='Hello X3DJSAIL'/>
> 
> <             <Viewpoint DEF='TopDownView' description='top-down view from above' orientation='1 0 0 -1.570796' position='0 100 0'/>
> 
> <         </ViewpointGroup>
> 
> ---
> 
>  >         <ViewpointGroup description='Available viewpoints'/>
> 
> You will see the missing Viewpoint’s (children of ViewpointGroup) as above.  Also jjs will generate significant output.
> 
> I can’t connect through svn, so I may be out of date.
> 
> John
> 
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
> 
> *From: *Don Brutzman <mailto:brutzman at nps.edu>
> *Sent: *Wednesday, June 6, 2018 9:41 AM
> *To: *John Carlson <mailto:yottzumm at gmail.com>
> *Cc: *x3d-public at web3d.org <mailto:x3d-public at web3d.org>
> *Subject: *Re: X3DJSAIL, X3dToJava.xslt and DOM X3DLoaderObject testing:anotherClassCastException
> 
> 1. Hi John, finally getting back to this one.
> 
> On 4/30/2018 3:15 PM, John Carlson wrote:
> 
>  > Previously reported problem, now assigned to the X3DLoaderObject, I believe.
> 
>  >
> 
>  > No Viewpoint children in X3D or JSON output.
> 
> Not sure what that means?  Viewpoint node typically does not have any children, except perhaps for a Metadata* node or an IS/connect.
> 
>  > Is a problem with X3DLoaderObject, looks like another class cast exception.  X3DJSONLD was eliminated from the problem by printing out the DOM object, and verifying the Viewpoint objects were there.   See x3d-code/www.web3d.org/x3d/stylesheets/java/nashorn/examples/Quotes.js.
> 
>  >
> 
>  > Can be regenerated by running `ant test.nashorn` in x3d-code/www.web3d.org/x3d/stylesheets/java
> 
>  >
> 
>  > See output in nashorn/examples/Json.{json,x3d}
> 
>  >
> 
>  > John
> 
> OK have recently updated to Java JDK 1.8.0_172 and adjusted PATH to confirm jjs is running OK.
> 
> Have also synchronized X3DJSAIL sudirectory nashorn/ and contents with subversion.
> 
> I get the following outputs when running test.nashorn build target:
> 
> ============================================================
> 
> ant -f E:\\x3d-code\\www.web3d.org\\x3d\\stylesheets\\java test.nashorn
> 
> test.nashorn:
> 
> ===========================================
> 
> ant nashorn/build.xml test.nashorn
> 
> X3D Nashorn SAI Library.test.nashorn:
> 
> Compile:
> 
> Compiling 1 source file to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\classes
> 
> Compiling 1 source file to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\classes
> 
> Copy:
> 
> Copying 1 file to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\nashorn\examples
> 
> Copying E:\x3d-code\www.web3d.org\x3d\stylesheets\java\examples\HelloWorldProgramOutput.x3d to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\nashorn\examples\HelloWorldProgramOutput.x3d
> 
> Copying 1 file to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\nashorn\examples
> 
> Copying E:\x3d-code\www.web3d.org\x3d\stylesheets\java\examples\HelloWorldProgramOutput.json to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\nashorn\examples\HelloWorldProgramOutput.json
> 
> Run:
> 
> parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes, parsed using Document Object Model (DOM) X3DLoader
> 
> parameter: "-tojs" for conversion to X3DJSONLD JavaScript source
> 
> parameter: "-toFile" "nashorn/examples/HelloWorldProgramOutput.Nashorn.js" for result file name root nashorn/examples/HelloWorldProgramOutput.Nashorn
> 
> convert to JS JavaScript:
> 
> Warning: toFileJavaScript() is overwriting prior file nashorn/examples/HelloWorldProgramOutput.Nashorn.js
> 
> Script DEF=colorTypeConversionScript contains CDATA source-code text, copied as "#sourceText" using "strings" mode
> 
> Script DEF=MaterialModulatorScript contains CDATA source-code text, copied as "#sourceText" using "strings" mode
> 
> TypeError: input.readAllBytes is not a function
> 
> Error: Cannot read file [E:\x3d-code\www.web3d.org\x3d\stylesheets\java\nashorn\node_modules\xmldom\package.json]:
> 
> [Error] TODO problem handling local exception within CommandLine, exiting
> 
> org.web3d.x3d.sai.X3DException: ScriptException when processing fileName nashorn\examples\HelloWorldProgramOutput.Nashorn.js.intermediate.js, unable to save result: javax.script.ScriptException: Error: Cannot load JSON file in nashorn/jvm-npm.js at line number 216 at column number 8
> 
>                  at org.web3d.x3d.jsail.Core.X3DObject.toFileJavaScript(X3DObject.java:1662)
> 
>                  at org.web3d.x3d.jsail.CommandLine.run(CommandLine.java:628)
> 
>                  at org.web3d.x3d.jsail.CommandLine.main(CommandLine.java:163)
> 
> parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes, parsed using Document Object Model (DOM) X3DLoader
> 
> parameter: "-toJSON" for conversion to JSON encoding
> 
> parameter: "-toFile" "nashorn/examples/HelloWorldProgramOutput.Java.json" for result file name root nashorn/examples/HelloWorldProgramOutput.Java
> 
> convert to JSON:
> 
> Warning: toFileStylesheetConversion(X3dToJson.xslt) is overwriting prior file nashorn/examples/HelloWorldProgramOutput.Java.json
> 
> Script DEF=colorTypeConversionScript contains CDATA source-code text, copied as "#sourceText" using "strings" mode
> 
> Script DEF=MaterialModulatorScript contains CDATA source-code text, copied as "#sourceText" using "strings" mode
> 
> file conversion successful: HelloWorldProgramOutput.Java.json (39749 bytes)
> 
> parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes, parsed using Document Object Model (DOM) X3DLoader
> 
> parameter: "-toX3D" for conversion to X3D encoding
> 
> parameter: "-toFile" "nashorn/examples/HelloWorldProgramOutput.Java.x3d" for result file name root nashorn/examples/HelloWorldProgramOutput.Java
> 
> convert to X3D:
> 
> Warning: toFileX3D() is overwriting prior file nashorn/examples/HelloWorldProgramOutput.Java.x3d
> 
> file conversion successful: HelloWorldProgramOutput.Java.x3d (20956 bytes)
> 
> ===========================================
> 
> ============================================================
> 
> As you can see, the exception is in nashorn/jvm-npm.js:
> 
>                  TypeError: input.readAllBytes is not a function
> 
> Header in that file indicates that you have modified it.
> 
> Specific javascript code block of interest:
> 
>     function readFile (filename, core) {
> 
>       var input;
> 
>       try {
> 
>         if (core) {
> 
>           var classloader = java.lang.Thread.currentThread().getContextClassLoader();
> 
>           input = classloader.getResourceAsStream(filename);
> 
>         } else {
> 
>                  input = new java.io.FileInputStream(filename);
> 
>         }
> 
>         return new java.lang.String(input.readAllBytes());
> 
>       } catch (e) {
> 
>         System.err.println(e);
> 
>         throw new ModuleError('Cannot read file [' + filename + ']: ', 'IO_ERROR', e);
> 
>       }
> 
>     }
> 
> JDK 8 Javadoc for java.io.FileInputStream does not provide a "readAllBytes()" method.  (Nor does JDK 1.9; however I am currently holding at 1.8 to stay compatible with Netbeans 8.)
> 
>                  https://docs.oracle.com/javase/8/docs/api/java/io/FileInputStream.html
> 
> So it looks like you need another method.
> 
> A search for "java.io.FileInputStream readAllBytes" provides a number of hits.  For example:
> 
>                  File to byte[] in Java
> 
>                  https://stackoverflow.com/questions/858980/file-to-byte-in-java
> 
> 2. Continuing with your prior error console also appears fruitful:
> 
>  >       [exec] [X3DLoaderObject error] Incorrectly handled object construction, current elementObject=ViewpointGroup (ViewpointGroup), child=Viewpoint, java.lang.ClassCastException: org.web3d.x3d.jsail.Navigation.ViewpointGroupObject cannot be cast to org.web3d.x3d.sai.Grouping.X3DGroupingNode
> 
>  >
> 
>  >       [exec] java.lang.ClassCastException: org.web3d.x3d.jsail.Navigation.ViewpointGroupObject cannot be cast to org.web3d.x3d.sai.Grouping.X3DGroupingNode
> 
>  >
> 
>  >       [exec]     at org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:1146)
> 
>  >
> 
>  >       [exec]     at org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:542)
> 
>  >
> 
>  >       [exec]     at org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:542)
> 
>  >
> 
>  >       [exec]     at org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:430)
> 
>  >
> 
>  >       [exec]     at org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:399)
> 
>  >
> 
>  >       [exec]     at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$372$Json$cu1$restOf.:program(nashorn/examples/Json.js:15)
> 
>  >
> 
>  >       [exec]     at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:655)
> 
>  >
> 
>  >       [exec]     at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
> 
>  >
> 
>  >       [exec]     at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)
> 
>  >
> 
>  >       [exec]     at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.apply(Shell.java:519)
> 
>  >
> 
>  >       [exec]     at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.runScripts(Shell.java:448)
> 
>  >
> 
>  >       [exec]     at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.run(Shell.java:186)
> 
>  >
> 
>  >       [exec]     at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:104)
> 
>  >
> 
>  >       [exec]     at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:80)
> 
> Looks like it was trying to treat ViewpointGroup like a X3DGroupingNode - but it is not.  ViewpointGroup is not a X3DGroupingNode node, and can only contain a Metadata* node, Viewpoint/OrthoViewpoint/GeoViewpoint and other ViewpointGroup nodes.
> 
> This might have been fixed already as part of the many DOM loader improvements performed; not seeing that error in my console.  Worth retesting if you can address the readAllBytes issue.
> 
> I've added a warning to X3D tooltips to clarify that.
> 
> Hope next round of improvement/testing can sort this one out fully.
> 
> all the best, Don
> 
> -- 
> 
> Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
> 
> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
> 
> X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman
> 


all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman




More information about the x3d-public mailing list