Java Netbeans error - java

I've been following the 'Netbeans E-Commerce tutorial', and have am currently on this step:
http://netbeans.org/kb/docs/javaee/ecommerce/entity-session.html
I have fully configured my Window 7 account as per that page, with NetBeans 6.9.1, Glassfish server and MySQL.
I'm getting an error 500 when executing 'Category' page (log extract below). The error manifests itself when I complete step 3 in the 'selected category' sub-section of the 'Accessing Data with EJBs' this page. The line in question is:
// get selected category
selectedCategory = categoryFacade.find(Short.parseShort(categoryId));
If I comment this line out, the bug goes away.
The log file snippet is here:
[#|2010-09-29T18:32:32.570+0100|WARNING|glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=30;_ThreadName=http-thread-pool-8080-(2);|StandardWrapperValve[Controller]: PWC1406: Servlet.service() for servlet Controller threw exception
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5017)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4805)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2004)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
at $Proxy355.find(Unknown Source)
at session.__EJB31_Generated__CategoryFacade__Intf____Bean__.find(Unknown Source)
at controller.ControllerServlet.doGet(ControllerServlet.java:68)
Line 68 in the ControllerServlet code is the one identified above.
My experience with both Java and Netbeans is sufficiently light that I'm not even sure how to go about starting to debug this. I've followed the tutorial pretty closely, so it should not be something I've missed - but mistakes do happen.
I understand an outright solution based on the information contained would be difficult. If there is any further information required, please ask. Failing that, if anyone has any suggestions on how I can further investigate this on my own, I'd be very grateful.
I always think cracking problems is the best way to learn, but it is pretty frustrating as well.
Update:
I've been running through the NetBeans debugger. It appears that the problem is with the cast code (Short.parseShort(categoryId)). When I replace this with a simple numeral it works.
e.g. this code works
// get selected category
selectedCategory = categoryFacade.find(1);
Does anyone have any ideas why the cast is failing? categoryId is confirmed as a string with a value of "1" in the debugger...

Okay, I've cracked this. It was obviously my fault...
The table identity should have been set up as a short, instead I set it up as an integer. Therefore by casting the 'categoryId' string to short and passing it into the find method, I was passing in the wrong data type.
Replacing the 'Short.parseShort(categoryId)' argument with a 'Integer.parseInt(categoryId)' fixed the problem.
For those that took the time to read this; thank you.

Related

JPAAppender blob

I am testing the log4j JPAAppender these days. After hours of work, I encountered just as same problem as others did.(if you search for JPAAppender, you will get that the log4j JPAAppender got a bug which keeps persisting garbage of a column of blob in size is huge for database). After that, I tried to download the source code from its official website and rewrote my own code which has exactly same class name and all the same functions in source code apart from a tiny modify I made to avoid entitymanager persisting garbage into database.
#Transient
private final LogEvent wrappedEvent;
here it is as you can find in log4j 2.7,package
package org.apache.logging.log4j.core.appender.db.jpa;
After doing that with full of hope that I might make it right, I ran my application and I got this error:
2018-01-29 17:18:44,543 main ERROR Entity class [com.log4jtest.demo.logger.JpaLogEntity] does not extend AbstractLogEventWrapperEntity.
So, what can I do? I really wanna use this appender.
maybe you might do the following, I will appriciate it:
1. tell me how to extend my own class without the error ocured
2. maybe you have got some brilliant solution, pls share.
thanks in advance.

Is it a good practice to log line number in error code to the user?

I have been tasked with logging the line number as part of the error code shown to the user. Currently I am using:
StackTraceElement[] stackTraceElement = e.getStackTrace();
lineNumber = stackTraceElement[0].getLineNumber();
I know that the above approach may fail depending on the JVM version.
Also, I have seen the PatternLayout where it is mentioned that "Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue.".
Since this message will be presented to the user, should I still log the line number as part of the error code? I am trying to understand the pros and cons of this approach. Also, does the log4j warning apply only to its own implementation or rather is it a warning against location information generally?
Well, generally speaking your program should report two kind of errors:
The errors that are for the user (when the user is not doing what is expected from him), which should actually be better called "feedback" to help him feed your program with the right data (that's good UX practice).
The errors that are generated because of a bug, which are actually not targeted at the user, but at you the developer, sadly through the user. Then yes, it might be a good idea to log line numbers (or give your errors unique names/identifiers so that you can trace easily where it's been sent from). But a better idea is to then use a framework to report such issues directly to you through Internet (good practice being to ask for permission first).
What you should show to the user is what went wrong and what he can do about it, if anything. The line number information needs to be available, e.g. via a 'More details' button, in case he needs to raise a support ticket, but you don't want to frighten him or confuse him with it up front. Just look at how many stack traces get misread or indeed ignored completely here, and this community is supposed to be computer programmers.
Generally its better if your program doesn't give errors, and can receive all input, and give you tips on how to use the application. This will give users a much better experience if you want them to buy your product, etc.. If your program does give errors, it will not be helpful for the user to know the line number. You however will want to know the line number, so you should make it display a message of some sort that tells the user to email you the stack trace when the error occurs. Or you could have it report the error message automatically and email it to you.
Sorry, I'm a bit late I was unclear what the question was asking, so I posted this as a comment, but clearly it is an acceptable answer.

UUID.randomUUID -> java.lang.StackOverflowError?

The title explains the problem I think, trying to create a random Id for an Object, I'm getting the following exception:
java.lang.StackOverflowError
at sun.security.provider.ByteArrayAccess.b2iBig64(ByteArrayAccess.java:274)
at sun.security.provider.SHA.implCompress(SHA.java:122)
at sun.security.provider.SHA.implDigest(SHA.java:103)
at sun.security.provider.DigestBase.engineDigest(DigestBase.java:186)
at sun.security.provider.DigestBase.engineDigest(DigestBase.java:165)
at java.security.MessageDigest$Delegate.engineDigest(MessageDigest.java:576)
at java.security.MessageDigest.digest(MessageDigest.java:353)
at sun.security.provider.SecureRandom.engineNextBytes(SecureRandom.java:226)
at java.security.SecureRandom.nextBytes(SecureRandom.java:455)
at java.util.UUID.randomUUID(UUID.java:145)
I don't think that anyone can tell me what is going on since I provide little information -> I know that.
The thing is: I have not any other information, I just create a randomUUID and it crashes.
So I'm just asking for ideas, since I don't find any googling this exception.
Thanks in advance.
EDIT:
Answer provided by
m0skit0 and scotth
Without noticing that the method which lead to an object creating a UUID was called nonstop I - well - did not notice that a huge amount of UUIDs was generated, which lead to the stackoverflow.
Thank you!

Source not found exception

In my application i have a JSP file named "Transferdatanew.jsp". When I am going to use my application, I am getting an exception as numberformatexception, but when I clicked there I am getting a message as "source not found for org.apache.jsp._Transferdatanew".
What does this mean? Please help me. I am new to Java.
Its pretty clear that there is a problem in the 'Transferdatanew.jsp'. I'd venture so far as to say that the jsp is receiving an input that is not in the numerical format it expects.
You should not be worried about 'Source not found exception' unless you want to see the source .... which will be in one of the $TOMCAT_HOME/work subfolders.

Don't understand why I am getting this - 'Error: Value storage corrupted: negative offset'

I just started using IntelliJ-IDEA, and I don't know if the problem resides with the IDE or not. I'm assuming not but I have no idea. I've spent quite a lot of time googling this error to no avail.
The error comes about at compile time. The weird thing is that I returned my code to the way it was before the error was showing up and it is still being thrown. Here is a little bit of my code that I believe is causing the problem. But I think it might be something besides my code.
import org.joda.xpath.XPath;
private XPath componentXPath;
private List list;
this.componentXPath = XPath.newInstance("(//rss/channel/item)");
Document doc = jiraAdapter.fetch("path to XML file");
list = componentXPath.selectNodes(doc);
The componentXPath.selctNodes(doc) is somehow causing the problem. If i remove this line, then it compiles fine, but I need to get a list of all the nodes to work with.
The error shows up in the messages pane: Error: Value storage corrupted: negative offset
Any help would be greatly appreciated.
What IDEA version do you use? Try File | Invalidate Caches and then rebuild the project.

Categories

Resources