Getting exception when trying to generate Jasper Report - java

I'm trying to generate a report with Jasper Reports 5.6.0 but I always end up getting two exceptions of the following sort:
UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JEditorPane[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,caretColor=,disabledTextColor=,editable=true,margin=,selectedTextColor=,selectionColor=,kit=,typeHandlers=]
java.lang.Error
at javax.swing.UIDefaults.getUIError(UIDefaults.java:731)
at javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:130)
at javax.swing.UIDefaults.getUI(UIDefaults.java:761)
at javax.swing.UIManager.getUI(UIManager.java:1016)
at javax.swing.text.JTextComponent.updateUI(JTextComponent.java:338)
at javax.swing.text.JTextComponent.<init>(JTextComponent.java:312)
at javax.swing.JEditorPane.<init>(JEditorPane.java:196)
at javax.swing.JEditorPane.<init>(JEditorPane.java:288)
at net.sf.jasperreports.engine.util.JEditorPaneHtmlMarkupProcessor.convert(JEditorPaneHtmlMarkupProcessor.java:80)
at net.sf.jasperreports.engine.fill.JRFillTextElement.processMarkupText(JRFillTextElement.java:1018)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:546)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:488)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:456)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2067)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:788)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:298)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:152)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:963)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:892)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:114)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:668)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:649)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:971)
Despite the exceptions, the report is generated, but with two missing fields, both of which should be filled with the value of the same object property. And since I have two exceptions that are exactly the same, I suspect the exceptions are the reason these fields are missing.
I have checked the object passed to Jasper Reports and the property that fills the missing fields has a value, so I believe it's not a coding problem.
I know that it'd be easier if I put the content of the .jrxml file in here but it belongs to a client, so that will not be possible. Still, any help would be appreciated.
The application is an API running on Fuse Karaf 7.3.

Related

NoSuchMethodError when calling getDeclaredAnnotation()

I have a running application where once I clicked on a 'Edit' link of a table, I'm getting an error in the log of NoSuchMethodError and the control stays in the current page, not proceeding to the edit page.
Below piece of code has been hit while getting the error;
Field[] fields = entityObj.getClass().getDeclaredFields();
for(int i=0;i<fields.length;i++){
Field field =fields[i];
field.setAccessible(true);
if(field.getDeclaredAnnotation(EmbeddedId.class)!=null){
return true;
}
}
return false;
In the above code at the line,
if(field.getDeclaredAnnotation(EmbeddedId.class)!=null)
I'm getting the particular error.
Also mentioning the log as below;
Caused by: java.lang.NoSuchMethodError: java.lang.reflect.Field.getDeclaredAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
at com.sprint.neo.querymodel.common.QueryObjectUtil.checkEnitityIsHasEmbeddedId(QueryObjectUtil.java:131)
at com.sprint.neo.querymodel.common.EntityManager.getEntityObject(EntityManager.java:89)
at com.sprint.neo.querymodel.common.EntityManager.loadEntityObject(EntityManager.java:72)
at com.sprint.neo.querymodel.common.EntityManager.entityload(EntityManager.java:60)
at com.sprint.neo.querymodel.common.EntityManager.loadAndGetEntityObject(EntityManager.java:56)
at com.sprint.neo.querymodel.common.QueryObjectUtil.getListOfEntityObject(QueryObjectUtil.java:718)
at com.sprint.neo.querymodel.common.QueryObjectCache.excuteUpdate(QueryObjectCache.java:251)
at com.sprint.neo.querymodel.common.QueryObjectRow.excuteUpdate(QueryObjectRow.java:298)
at com.sprint.neo.engine.controller.actions.TaskViewEditAction.edit(TaskViewEditAction.java:83)
The control should proceed to the edit jsp page as all the jsp are implemented correctly.
What I'm doubting about the error from the log is that, if any jar file is missing regarding Reflection api.
Please suggest me a solution to overcome this problem. Any valuable advise will be helpful. Thanks a lot.
You are using the method Field.getDeclaredAnnotation(Class). This method was introduced in Java 8. It is not available in Java 7 and earlier. You need to upgrade your JDK.
Field is a subclass of AccessibleObject and inherits the method from that class. See the Javadoc: It says “Since: 1.8” which is the version for Java 8 in the internal numbering scheme.

Java exception error during RJDBC::dbConnect: how to silently ignore?

I am trying to connect to a SAS-driven remote database from within R, using RJDBC. The first time I do a dbConnect, I get an error:
Error in .jcall(drv#jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1],
: java.lang.NoClassDefFoundError: com/sas/net/crypto/CryptoException
When I do the dbConnect a second time after the first call, it connects fine, and I get back an object of class JDBCConnection.
I looked in the sas.core.jar file (from the latest 94M2 SAS JDBC drivers), and can see CryptoException listed in there. However, I am also curious why it was trying to throw a CryptoException.
Question 1: How can I silently ignore the error on the first dbConnect call?
Question 2: Why was it trying to throw a CryptoException? What can I do to prevent this? (This may cancel question 1.)
This is the same question as shared on the SAS Support Communities page:
https://communities.sas.com/thread/80620
There you shared the code you are using
https://github.com/wthielen/wrds/blob/7edfbfe89ddc329618be72e591cc0bd50e294ea4/R/wrds.R#L47
In this code, the problem appears to be that you are trying to set the classpath before initializing the JVM. Using .jinit() before the call to .jaddClassPath should correct the issue. In the doc for .jinit and since you are developing a package, you may want to use .jpackage instead of .jinit
https://www.rforge.net/doc/packages/rJava/jpackage.html
I was having the same problems and tried the above solutions with no change.
The solution on my computer was modifying the .Renviron file which holds the classpath to the java drivers. Replacing "JDBC_Drivers" with "WRDS_Drivers" was all that was needed:
CLASSPATH="C:/Users/nicol/Documents/WRDS_Drivers/sas.core.jar;C:/Users/nicol/Documents/WRDS_Drivers/sas.intrnet.javatools.jar"

Subreport trouble in iReport 0.4.1

I am using iReport 0.4.1 and JasperReports 0.6.3, and I'm facing the trouble trying to generate a subreport:
I set in Java code .jasper subreport path, it's correct, but putting wrong path for test, no errors happen;
In subreport, putting a field for test, again no errors happen (i.e., the subreport is not accessed...);
I tried to access subreport list by two ways: as parameter and as a main report bean field (it's not the case: in fact I have two not-related reports to print in the same page, so that's why the subreport);
In almost all tries, when didn't happen error, appears a blank where subreport's data had to be
PS.: I put the subreport in Detail band, with main report data.
Could somebody help me? - both reports code below.
PS 2: I can't change versions, it's a new report in an existent structure, with this iReport and JasperReports version.
Java report calls:
parameters.put("subreportPath", projetoPath + "<CAMINHO>\\" + "xxxzz.jasper"
.................
parameters.put("ListaComparativoSaldos", listaSubreport);
//ABAIXO: nao funcionou
//parameters.put("ListaComparativoSaldos", new JRBeanCollectionDataSource(listaSubreport));
.................
return JasperFillManager.fillReport(is, parameters, new JRBeanCollectionDataSource(data));

Spring, NotReadablePropertyException and Glassfish version

I am working on a web-application that uses Spring MVC.
It has been working fine on Glassfish 3.0.1, but when migrating to Glassfish 3.1, it started acting strange. Some pages are only partially showing, or showing nothing at all, and in the log, a lot of messages of this type:
[#|2012-08-30T11:50:17.582+0200|WARNING|glassfish3.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=69;_ThreadName=Thread-1;|StandardWrapperValve[SpringServlet]: PWC1406: Servlet.service() for servlet SpringServlet threw exception
org.springframework.beans.NotReadablePropertyException: Invalid property 'something' of bean class [com.something.Something]: Bean property 'something' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:729)
at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:576)
at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:553)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:719)
at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99)
at org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:226)
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:120)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:164)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:127)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
at org.springframework.web.servlet.tags.form.TextareaTag.writeTagContent(TextareaTag.java:95)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
The error message isn't incorrect, because the property in question does not have a setter-method (gets its value through the constructor). But like I said, this has not been a problem when using Glassfish 3.0.1, only when using it on the new server with Glassfish 3.1.
Does anyone know if there is something in the Glassfish version that might cause this? Or is it some kind of configuration that is missing on the new server?
Some code:
Controller:
#ModelAttribute
public SomethingContainer retriveSomethingContainer(#PathVariable final long id {
return somethingContainerDao.retrieveSomethingContainer(id);
}
#InitBinder("somethingContainer")
public void initBinderForSomething(final WebDataBinder binder) {
binder.setAllowedFields(new String[] {
"something.title",
"something.description",
});
}
SomethingContainer:
#Embedded
private final Something something = new Something();
public Something getSomething() {
return something;
}
//no setter
public String getDescription() {
return something.getDescription();
}
Update:
Restarting Glassfish actually removes the problem - temporarily. I suspect that it might have something to do with the loading of the custom binders, we had some problems with out of memory errors, which I thought had something to do with it, but that has been fixed without fixing this problem.
Update 2:
On the 3.0.1 server, the one of the jvm arguments was -client. On the 3.1-server, it was -server. We changed it to -client, and this made the frequency of the error go down a lot, it was happening every other day with -server, took 2 weeks for it to happen with -client.
Update 3:
Some information about the servers (more can be added if requested..)
Server1 (the working one):
Windows Server 2003
Java jdk 6 build 35
Glassfish 3.0.1 build 22
-xmx 1024m
Server2 (the one with problems):
Windows Server 2008 64-bit
Java jdk 6 build 31
Glassfish 3.1 build 43
-xmx 1088m
-xms 1088m
We are using Spring version 3.1.0.
Update 4:
I recreated the error by renaming a field in a jsp to something that does not exist in the modelattribute.
But, more importantly, I noticed something: The fields where the system can't find the getters are often fields of superclasses of the ones that are referenced in the modelattribute. To continue my example, the SomthingContainer is really like this:
public class SuperSomethingContainer {
[...]
private Something something;
public Something getSomething() {
return something;
}
}
public class SomethingContainer extends SuperSomethingContainer {
[...]
}
The reference in the controller stays as is, so it's referencing a field that is in the superclass of the object in question.
Update 5:
I tried connecting to the production server with a debugger after the error occured. I put a breakpoint on the return statement of a controller-method returning the object with the error, and tried to see if I could access the field with problems at the time. And that I could, so the problem must lie within Spring MVC/the generated jsp-classes.
(Also, the field in error was of the type "someobject.something[0].somethingelse[0]", but when the somethingelse-list was empty, there was no error! To me, this implies that it somehow can't find the get-method of a list(?))
Update 6:
It seems that the problem has to do with the generation of Java-classes from the jsps. We have not used precompile jsps when deploying, so they are compiled when first used. The problem occurs the first time a page is visited, and the jsp compiled. I also noticed that once the problem has occured, jsps that are compiled after will all give errors. I've kept a few of the problem generated java files, and upon the next restart I will compare them to the working ones. Getting closer :)
Update 7:
Compared the compiled jsp java files that resulted in an error with ones that did not, and there was no difference. So that kinda leaves that out.
So, I now know that the Java object leaving the controller is fine (checked with debugger), and the java class generated from the jsp is fine. So it must be something in between, now I need to find out what...
Update 8:
Another round of debugging, and narrowed the problem down some more. It turns out that spring does some caching of the properties belonging to the various classes. In org.springframework.beans.BeanWrapperImpl, method getPropertyValue, there is the following:
private Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
String propertyName = tokens.canonicalName;
String actualName = tokens.actualName;
PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
if (pd == null || pd.getReadMethod() == null) {
throw new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName);
}
The problem is that the cachedIntrospectionResults does not contain the property in question, it contains every other property of the class though. Will need to dig some more to try to find out why it is missing, if it's missing from the start or if it gets lost somewhere along the line.
Also, I've noticed that the missing properties are those that do not have setters, only getters. And, it seems to be context aware, as indicated by the stacktrace. So not finding a property when visiting one page does not mean that its not available when visiting another.
Update 9:
Another day, more debugging. Actually found some good stuff. The getCachedIntrospectionResults() call in the previous code block wounded up calling CachedIntrospectionResults#forClass(theClassInQuestion). This returned a CachedIntrospectionResults object, containing far from all of the properties expected (11 of 21). Going into the forClass-method, I found:
static CachedIntrospectionResults forClass(Class beanClass) throws BeansException {
CachedIntrospectionResults results;
Object value = classCache.get(beanClass);
if (value instanceof Reference) {
Reference ref = (Reference) value;
results = (CachedIntrospectionResults) ref.get();
}
else {
results = (CachedIntrospectionResults) value;
}
if (results == null) {
//build the CachedIntrospectionResults, store it in classCache and return it.
It turned out that the CachedIntrospectionResults returned was found by classCache.get(beanClass). So what was stored in the classCache was corrupted/did not contain all that it should. I put a breakpoint on the classCache.get(beanClass)-line, and tried running this through the debugger:
classCache.put(beanClass, null);
When allowing the method to finish, and rebuild the CachedIntrospectionResults, things started working again. So, what is being stored in the classCache is out of sync with what would and should be created if it was allowed to rebuild it. Whether this is due to something going wrong the first time it is built, or if the classCache is corrupted somewhere along the line I do not currently know.
I'm starting to suspect that this has something to do with classloaders, as I've previously experienced problems due to changes in the way the classloader works when updating Glassfish..
There may be more than one possible reason. I am not sure about the actual but I can give you the way to find out the problem
Step 1: on server 2 machine deploy application on Glassfish 3.0.1 build 22 , now if it works fine on the server 2 machine that it means there might be problem with the libraries of Glass fish, following can be reason for this problem
Any library that is missing in the Glassfish 3.1 build 43 that is in Glassfish 3.0.1 build 22. you can solve by copying all libraries from working Glassfish server to new server.
My be the libraries of Glassfish is conflicting with spring version. [Similliar kind of problem I have faced on tomcat and when i replaced my spring libraires from 3.0.1 to 3.0.3 it worked for me] , so replace your spring libraries with latest one.
Step 2: and if the result of step1 is that application is not running on server 2 machin on Glassfish 3.0.1 build 22 there may be following reason
if any libraries that you have pasted on java lib either not included in this server machine or having different versions.
Any folders that are set on classpath or using any environment variables on server 1, either does not exist on server 2 or don't have the jars or having jars with diff versions
I got a colleague of mine investigate the error, and he was able to recreate it in a unit test. This was done by invoking the method that builds CachedIntroSpectionResults for a class, while at the same time stressing the jvm by adding strings to the memory, with very low memory settings. This approach made it fail 20/30000 times.
As to the cause of it, I only got an oral explanation, so I don't have all the details, but it was something like this: Java has its own introspection-results, and these are wrapped by Spring. The problem is that the java-results utilize soft references, which make them prone to garbage collections. So, when Spring was building its wrappers around these soft references at the exact same time that the garbage collector ran, it actually cleared some of the basis of what Spring was using, leading to properties being "lost".
The solution seems to be upgrading from Spring 3.1.0.RELEASE to Spring 3.1.3.RELEASE. Here, there are some changes, and Spring no longer wraps soft references when determining the properties of a class (soft reference are used in rare, special cases, instead of all the time). After upgrading the version of Spring, the error has not been reproducable through the unit test, it remains to see if this is the case through in practice use.
Update: It's been a few weeks, an no sign of the error. So updating Spring version worked :)
I think I've actually found a candidate for the cause of this.
After getting the error on one of the test-servers after a very short duration and little use, we did some additional checks on the cause. It turned out that the test-server had just half the available memory, which turned us into looking at it a bit more thoroughly. It turned out that it hadn't used up all its memory, but when using JConsole to investigate the memory usage of the different part of the new generation space on the heap, it turned out that one of the surivior spaces was packed full. I'm guessing that this made parts of it overflow, leading to the overflowed parts to be GC-ed or unreachable by not being where it was supposed to.
We have yet to verify that this is in fact the problem in the production environment as well, but once the error turns up again we will check, and if it is the case we will change some memory settings to allow more space for survival areas of the new generation heap. (-XX:SurvivorRatio=6 or something like that).
So it seems that larger Spring MVC applications has a need for a large survivor space, specially in newer versions of Glassfish.
Indeed, there had been an issue with the new introduced ExtendedBeanInfo class in Spring 3.1.0, which had been fixed in Spring 3.1.1 - see (https://jira.spring.io/browse/SPR-8347).

How to use Java Emitter Template (JET) to generate Java code from a a .xmi file created based on an EMF model

So, here is my problem, I have an Eclipse EMF project, and i have built a model, generated the corresponding code, and also programmed some framework classes by hand, that correspond to the model.
I have used the eclipse wizard to adapt the project to a Java Emitter Template (JET) Transformation project (and noticed that this did not generate the same configurations in the MANIFEST, that a JET Project created from scratch, does...)
I have created a JET file that creates a Java class to generate the code for the main class of the application, based on the input that goes into "argument".
Then I have created a Dynamic instance, and populated the created .xmi file with some nodes according to the model.
Now what I did was to create a JET Transformation running configuration, and i am trying to pass as input the .xmi file, and use onee of the only two things available in the Transformation ID combo box...
If I select Transformation ID to be jet2, I get this output in console:
templates/main.jet(8,1): <c:setVariable var='org.eclipse.jet.taglib.control.iterateSetsContext' select='true()'>
Trace: completed action.
templates/main.jet(29,1): <c:if test='isVariableDefined(''org.eclipse.jet.resource.project.name'')'>
Trace: processing body
templates/dump.jet(2,1): <c:dump select='/*' format='true' entities='true'>
Trace: completed action.
templates/main.jet(30,5): <ws:file template='templates/dump.jet' path='{$org.eclipse.jet.resource.project.name}/dump.xml'>
Trace: completed action.
Successful Execution
And if instead, I select Transformation ID to be org.eclipse.jet.transforms.taglib.doc (the only available other option), I get:
templates/control.jet(8,1): <c:setVariable var='jetPluginNS' select='''org.eclipse.jet'''>
Trace: completed action.
templates/control.jet(9,1): <c:setVariable var='tagLibrariesXP' select='concat($jetPluginNS, ''.tagLibraries'')'>
Trace: completed action.
templates/control.jet(15,1): <c:setVariable var='pluginNS' select='$org.eclipse.jet.resource.project.name'>
Trace: completed action.
templates/control.jet(16,1): <c:setVariable var='docPlugin' select='concat($org.eclipse.jet.resource.project.name, ''.doc'')'>
Trace: completed action.
templates/control.jet(21,5): <c:iterate select='/plugin/extension[#point = $tagLibrariesXP]' var='extension'>
Trace: loop initialized
templates/control.jet(21,5): <c:iterate select='/plugin/extension[#point = $tagLibrariesXP]' var='extension'>
Trace: finished loop
templates/control.jet(69,5): <c:iterate select='/plugin/extension[#point = $tagLibrariesXP]' var='extension'>
Trace: loop initialized
templates/control.jet(69,5): <c:iterate select='/plugin/extension[#point = $tagLibrariesXP]' var='extension'>
Trace: finished loop
Successful Execution
In either case, I dont get any generated Java class out of the generate method, and yet both say they are successful... also, by the console messages in first case, I see that a dump.xml file is generated with a kind of xmi to xml translation of that file, but without any association to Java or any of the methods i defined to be created in the JET generation class...
Also, if after generating the dump.xml file mentioned, i try to use it as input, it tells me that my Application object is not found or is abstract. In fact the one from the generated package is indeed an interface, but even if i try to use the Impl one i get the same error, and i dont even know if it is acting correctly because of all this procedure i took to get to this dump.xml file.
What am I doing wrong? can anyone please help me?
Thanks in advance!
Since you only had two choices for transformation id I'm going to say that you did not create a JET transform project. If you had then its transform id would have shown up in the drop down list in the configurations dialog.
I would start by using the new project wizard to create a new JET transform project. The default behavior of a new transform is to dump the input model into a file named dump.xml in the root directory of the same project that contains the input model file. When this JET project has been created then use the run configuration dialog to run the transform against your XML file. When you look at the dump.xml file that gets created you'll see the actual model that JET uses. EMF models can be cyclical but JET will adapt an EMF model into a subset that is hierarchical in nature.
Once you see the effective model (the one in the dump.xml file) then you can build or modify your templates to use that model and generate whatever files you need.
Also, the way your question is worded you seem to have built a single JET template for your class, but JET also needs a template, usually called main.jet, that acts as a controller in the MVC sense and which is responsible for applying other JET templates in the JET project to the model and specifying the resultant file names for the generated content.

Categories

Resources