How can I add to the "Error Log" section in Eclipse? - java

I am trying to make an Eclipse plugin that enables a student with no knowledge of English to code. So I want to take the errors of what he coded [in his own language], translate them and put them in the Error Log for him to see and understand.
How can I write in the "Error Log"?

I'm unclear of the use case here. But based on partial understanding, here is what you can do. You can wrap each exception/error with your exception hierarchy with language/locale of your choice and then print out wrapped error/exception into it. Keep this log file in the project path, so it will be accessible from within. Parse it and display it as and when it gets updated. So instead of checking the error log panel, you can see your log file for the reference.

Related

Eclipse - Clipboard exception "ClassNotFoundException"

I am developing an application in Eclipse, with frames. In some of the panels I allow the user to paste data from his clipboard. It is usually quiet. The problem is when what is on the clipboard has been copied from intelliJ (due to IntelliJ causing everything that is copied to become a serialized object) and results in an exception (ClassNotFoundException) and I can't catch it.
Does anyone know how to avoid this, in code?
Exception:
Exception "java.lang.ClassNotFoundException: com/intellij/codeInsight/editorActions/FoldingData"
while constructing DataFlavor for:
application/x-java-jvm-local-objectref;
class=com.intellij.codeInsight.editorActions.FoldingData
The obvious answer would be to catch the exception and ignore it.
If you can't do that, some possibilities are:
Develop a patch to Eclipse that allows a plugin to suppress these exceptions ... somehow1. Then submit an Eclipse bug report, providing your patch as a solution.
Get the user to add the Intellij "idea.jar" file to the Eclipse classpath so that Eclipse can deserialize these objects. You may then need to make further modifications to your plugin to allow it to make sense of the IDEA objects that you user is trying to copy and paste into Eclipse.
Document that your plugin does not support copy / paste from Intellij IDEA.
I couldn't see any way to stop Intellij from putting serialized objects into the clipboard.
UPDATE - I did some more research on this. The string
"while constructing DataFlavor for:"
appears in the source code for java.awt.datatransfer.SystemFlavorMap. That suggests that the problem is actually the same one as has been reported as Java bugs JDK-6606476 and 8246248. (In the latter case, the problem is triggered by certain kinds of JPEG files.)
Examining the source code suggests that it ought to be possible to work around this problem; e.g. by creating and registering a custom DataFlavor and implementing a DataContentHandler / DataContentHandlerFactory to take care of the conversion2. However, I can't give you specifics.
1 - It turns out that the problem is probably NOT in the Eclipse code base after all.
2 - Unless you fancy decoding Java serialization format by hand, I suggest you "deserialize" this stuff as content-free objects ... and get your application to quietly ignore DnD events for this kind of data.

What to log and what not to log using log4j?

I'm newbie to logging event for java program using log4j. I would like to know what to log and what not to log inside my log file because writing to log file for everything we have done in program affects the performance. Also, sometimes we write the sensitive information to the log file, for example, database name. Thus I would like to have insight view about what we should not write and what we should write into our log file.
Avoid PCI and PII data in case your logs ever got into the wrong hands. Basically if you wouldn't want a hacker getting a piece of information, then don't log it.

RFT: How can I export error messages generated on screen during playback

I'm writing a negative test script in order to deliberately generate error messages which will be displayed on the screen to the end user. I've written the script and it works, and I added a System.print in order to write the message to the console.
My question is how do I write this message to a txt file instead? I'd like to have the error message automatically added to a text file after each run.
Thanks
RFT does not provide any APIs to write to file as such. You will need to use Java to get things done.
Following link should help
how to create a file-stack overflow

I want to read the xml response displayed in the eclipse console to assert with the expected xml.

I want to read the xml responce displayed in the eclipse console to assert with the expected xml. Can somebody please help me to read the output from the console of eclipse while running my test....
I am not sure if you are trying to assert two XML's using Junit etc? Also I am not sure of what you mean by reading from Console?
If you are writing the code to assert using two XML's using Junit & XMLUnit Below link can help.
XML's Comparison
XML unit's Example Code
The Eclipse console simply displays what's printed to the standard output. If you aren't concerned about spurious output, then you can quite simply print whatever information might be useful to standard output, and it should end up there, assuming that you have the debugger properly attached to the running process.
I can't think of a ready way to do it automatically when an assertion fails, though, since it will most likely be local in scope (so you can't catch and rethrow the generated exception).
Simple calls to System.out.println() should give you a start.

Getting the actual jsp line number from a stack trace line number?

Here is the stacktrace:
...
org.apache.jsp.showcustomer_jsp._jspService(showcustomer_jsp.java:128)
org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
This is what I do:
Get the line number from the stacktrace, in this case 128.
Find the showcustomer_jsp.java file (and it isn't exactly obvious to look in /var/run/tomcat-6/Catalina/localhost/_/org/apache/jsp).
Open it and go to line 128.
Now, search the .jsp file for the whatever you found on line 128 in the _jsp.java file.
Boom! You're done!
Please, is there a simpler way to do this?
I have found this page on Eclipse WTP FAQ which explain how to configure Eclipse so that you can go to the generated java code clicking on the stacktrace.
I don't think you can. The JSP file is compiled into a servlet, and is not run directly. As the exception is thrown from this servlet, the line you have in the stack trace is the one from the class. The original line in the JSP is lost at this point.
Usually it is best to avoid writing code or throwing exceptions from a jsp, and encapsulate your logic in servlets and JSP tags, and use JSTL for control flow (if, forEach, etc.)
I used to program in Lex and Yacc which would generate C code, and you could enable #line pre-processor directives for debugging. When something happened in generated c code, then the IDE was smart enough to open the corresponding lex or yacc file, and not the generated c code. Surly

Categories

Resources