• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how to disable runtime warning??

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a java program that uses the built-in Transformer class to apply XSL to XML. The process of doing this is generating a "Compiler Warning" message (with details) to the console. At this time, I cannot change the XSL to get around this but at the same time, I don't want customers to see this and wonder what is wrong.

I've searched high and low for switches to "turn off" this warning both in the Xalan and Java documentation and have found none. Am I missing something??? Is there a way I can say "don't output warnings"?

I'm assuming the Transformer class is writing these messages to System.out or System.err. I also have a GUI that is redirecting this output to a TextArea window. My last resort may be to watch for these strings and filter them.

Thanks for any/all suggestions!
Kelly
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checkout if these XML frameworks are using Commons Logging/Log4J or other logging frameworks. If yes, you should be able to turn them off quite easily by modifying configuration files to include the packages/classes which are logging those warnings. Or you can simply remove all WARN messages altogether by increasing the allowed threshold.
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since I'm simply using the standard Java (JDK) library v1.5, I found the warning message I'm seeing in the source code and then traced through the code to see where it was actually printing it. It is printing the warnings using System.err.println (see Java source Parser.java in the printWarnings() method).
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can redirect the standard error an output streams. Have a look at the System class and you'll see ways to set these to OutputStreams other than the console.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this a compiler warning, or something you see at runtime? I suppose in some cases you might have a compiler warning at runtime, but this sounds strange. What is the exact text of the warning?

In some cases you might be able to suppress the warning with javac -Xlint:none. This is probably a bad idea, but you can try it to see if it's possible. Depending on what the warning is actually for, you might be able to replace "none" with something more specific, like javac -Xlint:-unchecked. However it's also quite possible from your description that this isn't really a compiler warning at all, in which case this won't have any effect.
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To answer Paul:

I'm currently re-directing System.out and System.err to a GUI text window. Unfortunately, there are some messages that my program is generating to each of these that the user must see because they are valid info or error messages. It is simply these couple of XSLT warnings that I do not want the user to see.

To answer Jim:

This is a warning I see at runtime (not compile time) when I call the transform() method on a Transformer object. The exact warning is:

Compiler warnings:
line ####: Attribute 'abcd' outside of element.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Kelly]: I'm currently re-directing System.out and System.err to a GUI text window. Unfortunately, there are some messages that my program is generating to each of these that the user must see because they are valid info or error messages. It is simply these couple of XSLT warnings that I do not want the user to see.

Can you redirect the streams somewhere else just for the duration of the call the transform(), then restore System.out and System.in to the GUI window redirection? This will work if there are no other warnings you need to see during the transform().

Alternately, you can create a filter of some sort that intercepts the messages before they're displayed, checks their content, and then passes on messages that don't look like the "Compiler warning" stuff you wish to eliminate. The difficulty of this will depend mostly on how standard the message formats are. Perhaps you can just always ignore a line that says "Compiler warning" and the next line after that, for example. Or perhaps there are other compiler warnings that you need to see. I don't know - you'll have to analyze the messages you get. I recommend that whenever you decide you ignore a warning, you at least copy the full text to a log file somewhere, so that a programmer can still debug what's going on even though the end user doesn't see the message. This is particularly important if there's a chance you are ignoring other compiler warnings besides the one you know about.
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm...good thoughts...

If I decide this is a temporary quick fix, I may try out the re-direct just before/after the transform that is generating the warnings. The permanent fix may simply be to address the warnings by re-working the XSL. I just don't have time for that right now.

But if not, your other thoughts are a good point.

Thanks!
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might also put a custom sub class of FilterWriter or FilterOutputStream (don't be confused by the class names, they are coincidence) somewhere in between System.out/err and your output TextArea, one that allows you to switch writing the string messages on and off. Might be more comfortable than redirection System.out/err alltogether just for the transformation.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that in Swing applications, you almost invariably have to deal with multithreading. In such an environment, the filter solution sounds like the more robust solution to me.
 
They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic