Drools Rule Template error [Error: unclosed #if{} block. expected #end{}] when placeholder is used - drools

drools rule template cannot be compiled if placeholder is used in subclass collection list.
I have this simple class structure
public class Parent {
private List<Child> children;
}
public class Child {
private String gender;
}
When placeholder #{gender} is used, ExternalSpreadsheetCompiler throw error
[Error: unclosed #if{} block. expected #end{}]
Parent($children: children)
Child(gender == "#{gender}") from $children
No issue when "MALE" is hardcoded in the template
Parent($children: children)
Child(gender == "MALE") from $children
Any idea? Thanks for your help.
Full error stack trace :
[Line: 42, Column: 0]
at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at org.drools.core.common.DefaultAgenda.handleException(DefaultAgenda.java:1291)
at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:442)
at org.drools.core.phreak.RuleExecutor.fireActivation(RuleExecutor.java:380)
at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:136)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:89)
at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1101)
at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1048)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1040)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1341)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1332)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1316)
at org.drools.template.parser.TemplateDataListener.finishSheet(TemplateDataListener.java:158)
at org.drools.decisiontable.parser.xls.ExcelParser.finishSheet(ExcelParser.java:277)
at org.drools.decisiontable.parser.xls.ExcelParser.processSheet(ExcelParser.java:212)
at org.drools.decisiontable.parser.xls.ExcelParser.parseWorkbook(ExcelParser.java:105)
at org.drools.decisiontable.parser.xls.ExcelParser.parseFile(ExcelParser.java:84)
at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:140)
at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:168)
at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:99)
at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:85)
at com.dhl.gssdemo.config.SpringDroolsConfig.addTemplateContent(SpringDroolsConfig.java:112)
at com.dhl.gssdemo.config.SpringDroolsConfig.classpathDrlKieBase(SpringDroolsConfig.java:102)
at com.dhl.gssdemo.config.SpringDroolsConfig$$EnhancerBySpringCGLIB$$583d8208.CGLIB$classpathDrlKieBase$0(<generated>)
at com.dhl.gssdemo.config.SpringDroolsConfig$$EnhancerBySpringCGLIB$$583d8208$$FastClassBySpringCGLIB$$25a5fef6.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at com.dhl.gssdemo.config.SpringDroolsConfig$$EnhancerBySpringCGLIB$$583d8208.classpathDrlKieBase(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 52 common frames omitted
Caused by: java.lang.RuntimeException: [Error: unclosed #if{} block. expected #end{}]

I had the same issue I think its related to resolving MVEL expression but I resolved it by using the following workaround (use $$ instead of $)
E.g in your case
Parent($children: children)
Child(gender == "#{gender}") from $$children

Related

NoSuchMethodException with "select new" after upgrading to Spring Data JPA 1.10.3

I encountered an issue after upgrading our Spring Data JPA from 1.9.2 to 1.10.3.
I have the following repository:
public interface ShipmentStatisticRepository extends JpaRepository<Shipment, Long> {
...
#Query("select new de.l.b.model.dto.shipment.ShipmentStatistic(s.createdYmd, count(distinct s.oid), count(op), sum(op.price)) " +
"from Shipment s " +
"join s.orderPosition op " +
"where s.created between ?1 and ?2 " +
"group by s.createdYmd")
List<ShipmentStatistic> findPerDayBetweenCreated(Date from, Date to);
...
}
When I call this method I get the following Exception:
org.springframework.dao.InvalidDataAccessApiUsageException: Could not instantiate Collection type: org.apache.openjpa.kernel.DelegatingResultList; nested exception is java.lang.IllegalArgumentException: Could not instantiate Collection type: org.apache.openjpa.kernel.DelegatingResultList
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:384)
at org.springframework.orm.jpa.DefaultJpaDialect.translateExceptionIfPossible(DefaultJpaDialect.java:122)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:436)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy154.findPerDayBetweenCreated(Unknown Source)
at de.l.b.hazelcast.map.ShipmentStatisticPerDayMapLoader.getShipmentStatistic(ShipmentStatisticPerDayMapLoader.java:40)
at de.l.b.hazelcast.map.AbstractShipmentStatisticMapLoader.load(AbstractShipmentStatisticMapLoader.java:38)
at de.l.b.hazelcast.map.AbstractShipmentStatisticMapLoader.loadAll(AbstractShipmentStatisticMapLoader.java:48)
at com.hazelcast.map.impl.MapStoreWrapper.loadAll(MapStoreWrapper.java:143)
at com.hazelcast.map.impl.mapstore.AbstractMapDataStore.loadAll(AbstractMapDataStore.java:56)
at com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore.loadAll(WriteBehindStore.java:205)
at com.hazelcast.map.impl.recordstore.BasicRecordStoreLoader.loadAndGet(BasicRecordStoreLoader.java:170)
at com.hazelcast.map.impl.recordstore.BasicRecordStoreLoader.doBatchLoad(BasicRecordStoreLoader.java:143)
at com.hazelcast.map.impl.recordstore.BasicRecordStoreLoader.loadValuesInternal(BasicRecordStoreLoader.java:129)
at com.hazelcast.map.impl.recordstore.BasicRecordStoreLoader.access$100(BasicRecordStoreLoader.java:54)
at com.hazelcast.map.impl.recordstore.BasicRecordStoreLoader$GivenKeysLoaderTask.call(BasicRecordStoreLoader.java:112)
at com.hazelcast.util.executor.CompletableFutureTask.run(CompletableFutureTask.java:67)
at com.hazelcast.util.executor.CachedExecutorServiceDelegate$Worker.run(CachedExecutorServiceDelegate.java:212)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)
Caused by: java.lang.IllegalArgumentException: Could not instantiate Collection type: org.apache.openjpa.kernel.DelegatingResultList
at org.springframework.core.CollectionFactory.createCollection(CollectionFactory.java:208)
at org.springframework.core.CollectionFactory.createCollection(CollectionFactory.java:151)
at org.springframework.data.repository.query.ResultProcessor.processResult(ResultProcessor.java:146)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:119)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:104)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 25 more
Caused by: java.lang.InstantiationException: org.apache.openjpa.kernel.DelegatingResultList
at java.lang.Class.newInstance(Class.java:427)
at org.springframework.core.CollectionFactory.createCollection(CollectionFactory.java:204)
... 39 more
Caused by: java.lang.NoSuchMethodException: org.apache.openjpa.kernel.DelegatingResultList.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 40 more
It looks like the repository can't resolve the correct constructor to fill my projection. With version 1.9.2 everything works fine.
This is my projection class:
public class ShipmentStatistic implements Serializable {
private Date date;
private long totalParcelsSent;
private long totalPositionsSent;
private long totalValue;
public ShipmentStatistic(Date date) {
this.date = date;
this.totalPositionsSent = 0;
this.totalParcelsSent = 0;
this.totalValue = 0;
}
public ShipmentStatistic(Date date, long totalParcelsSent, long totalPositionsSent, long totalValue) {
this.date = date;
this.totalPositionsSent = totalPositionsSent;
this.totalParcelsSent = totalParcelsSent;
this.totalValue = totalValue;
}
public ShipmentStatistic add(ShipmentStatistic other) {
this.totalPositionsSent += other.totalPositionsSent;
this.totalParcelsSent += other.totalParcelsSent;
this.totalValue += other.totalValue;
return this;
}
// getter and setter
}
I made a random shot and tried to add a default constructor but without success.
I can not see my error especially the only change a made was the framework update. We use OpenJPA 2.2.2 as Persistence API by the way. I upgraded to the current version 2.4.1 but this had no effect either.
Any suggestions? May this be a bug in Spring Data JPA in combination with OpenJPA?
From stacktrace, it looks like openjpa is searching for the default constructor. Could you try adding default constructor explicitly in ShipmentStatistic.java?
JPA specification mandates the use of default no-argument constructor.
http://openjpa.apache.org/builds/1.2.3/apache-openjpa/docs/jpa_overview_pc.html#jpa_overview_pc_no_arg

JPA - java.lang.IllegalArgumentException: The attribute [productName] is not present in the managed type

I am selecting the following columns using multiselect of Criteria API
Code snippet
criteriaQuery.multiselect(root.get(MasterCat_.prodId),
joinProduct.get(ProductList_.prName).alias("productName"));
criteriaQuery.orderBy(criteriaBuilder.desc
(root.get(mywrapperclass.getOrderBy()));
In above order by code snippet,I am passing productName from client.
and in constructor expression I have
public ProductListUtil(Long logId, String productName) {
this.logId = logId;
productName = productName;
}
The error I am getting is java.lang.IllegalArgumentException: The attribute [productName] is not present in the managed type.
How can I resolve this?
Exception stacktrace
java.lang.IllegalArgumentException: The attribute [productName] is not present in the managed type [EntityTypeImpl#5185929:ProductList [ javaType: class test.entity.ProductList descriptor: RelationalDescriptor(test.entity.ProductList --> [DatabaseTable(PRODUCT_LISTS)]), mappings: 8]].
at org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl.getAttribute(ManagedTypeImpl.java:148)
at org.eclipse.persistence.internal.jpa.querydef.FromImpl.get(FromImpl.java:312)
at test.service.ProductListService.getProductListsList(ProductListService.java:129)
at test.service.ProductListService.getProductLists(ProductListService.java:101)
at test.service.ProductListService.getProductLists(ProductListService.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
It is not saying there is no arg in the constructor ... it says there is no attribute in the class with that name.

JavaFX 8 TreeTableColumn setText ClassCastException

My situation is: I have a TreeTableView that has a TreeTableColumn. The Columns head text will be changed on runtime.
When I change the text through setText or textProperty().bind(...) before I show the stage, all works as expectet.
But if i change the text after showing the stage, I get a massive java.lang.ClassCastException.
I have tried this with Java SE 1.8.0 b132 and with Java 1.8.0_20 b17 EA.
Is there a workaround for this except recreating the TreeTableColumn?
My Sample Code:
TreeTableView<String> ttv = new TreeTableView<>();
TreeTableColumn<String, String> ttc = new TreeTableColumn<>();
ttc.setText("Hello");
ttv.getColumns().add(ttc);
ttv.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent t) {
ttc.setText("World");
}
});
Scene scene = new Scene(ttv);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
The Exception(after clicking on TreeTableView):
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:367)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:305)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:894)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassCastException: javafx.scene.control.TreeTableColumn cannot be cast to javafx.scene.control.TableColumn
at com.sun.javafx.scene.control.skin.TableHeaderRow$10.invalidated(TableHeaderRow.java:277)
at javafx.beans.WeakInvalidationListener.invalidated(WeakInvalidationListener.java:83)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:339)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:143)
at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
at javafx.scene.control.TableColumnBase.setText(TableColumnBase.java:189)
at com.kalasch.test.TreeTableTest.start(TreeTableTest.java:39)
at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
... 1 more
Exception running application com.kalasch.test.TreeTableTest
UPDATE 08/04/2014:
Submitted Bug report to javafx-jira:
https://bugs.openjdk.java.net/browse/JDK-8095931
UPDATE 08/05/2014:
Fix Version will be: 8u40
#thatjavaguy09 fix does work.
Greetings, Kalsch
Looking through the stack trace, it seems the issue is that your TreeTableColumn is trying to be casted into a TableColumn which is what is throwing the ClassCastException (since that is in fact an invalid cast).
It seems the call is coming from TableHeaderRow.invalidated. Looking at this method, I see where the cast is coming from.
private final InvalidationListener columnTextListener = new InvalidationListener() {
#Override public void invalidated(Observable observable) {
**TableColumn<?,?> column = (TableColumn<?,?>) ((StringProperty)observable).getBean();**
CheckMenuItem menuItem = columnMenuItems.get(column);
if (menuItem != null) {
menuItem.setText(getText(column.getText(), column));
}
}
};
This might be a bug with the JDK. I believe the correct cast should be to a TableColumnBase. I would submit this to their bug tracker:
https://javafx-jira.kenai.com/secure/Dashboard.jspa

How to resolve a Classloader related 'java.lang.LinkageError' when sending email from Tomee?

I am trying to send an email from my code that runs on Tomee 1.6
I have the following entry in the tomee.xml file.
<Resource
id="abc_mail"
type="javax.mail.Session"
>
mail.transport.protocol=smtp
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.smtp.socketFactory.fallback=false
mail.smtp.host=smtp.gmail.com
mail.smtp.port=465
mail.smtp.auth=true
mail.smtp.user=xyz#gmail.com
password=xyzpass
</Resource>
I have an ejb with the following declaration.
#Resource(name = "abc_mail")//, type = javax.mail.Session.class)
Session abcMailSession;
The code for sending the email is the following.
public void sendMessage(String addressTo, String subject, String messageText) {
try {
Message message = new MimeMessage(abcMailSession);
message.setFrom(new InternetAddress("abc#xyz.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(addressTo));
message.setSubject(subject);
message.setText(messageText);
Transport.send(message);
logger.info("Message sent successfully.");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
When calling this method I get the following error.
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.geronimo.mail.util.SessionUtil.getBooleanProperty(Ljavax/mail/Session;Ljava/lang/String;Z)Z" the class loader (instance of org/apache/openejb/util/classloader/URLClassLoaderFirst) of the current class, javax/mail/internet/MimeMessage, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/geronimo/mail/util/SessionUtil, have different Class objects for the type vax/mail/Session;Ljava/lang/String;Z)Z used in the signature
at javax.mail.internet.MimeMessage.isStrictAddressing(MimeMessage.java:1460)
at javax.mail.internet.MimeMessage.addRecipientsToList(MimeMessage.java:428)
at javax.mail.internet.MimeMessage.getAllRecipients(MimeMessage.java:400)
at javax.mail.Transport.send(Transport.java:48)
at co.uk.dakia.core.interfaces.impl.NotificationManagerImpl.sendMessage(NotificationManagerImpl.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:182)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:164)
at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:180)
at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:182)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:164)
at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:80)
at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:212)
at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:181)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:268)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:263)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:86)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:303)
... 47 more
Why do I get this error? I am not able to figure out the first line in the stack trace.
I have now solved this. The error occurs because the same class is being loaded by two different classloaders (tomcat and openejb ones), the class in question is javax.mail.Session
I added the following property to tomee's system.properties file
openejb.classloader.forced-skip=javax.mail
What this does it prevents openejb classloader from loading the javax.mail classes and therefore only tomcat classloader loads all the relevant classes required for sending email.

Solution to NullPointerException in my TestNG test case

I am trying to login Facebook by using multiple sets of login cridential from external excel sheet using TestNG but in between the code what i have written throws:
FAILED: f
java.lang.NullPointerException
at DataDriven.loginRetesting.f(loginRetesting.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Code:
#Test
public void f() throws Exception{
FileInputStream fi=new FileInputStream("E:\\workspace99\\SeleniumAutomations\\testdata\\LoginData.xls");
Workbook w=Workbook.getWorkbook(fi);
Sheet s=w.getSheet(0);
for (int i = 1; i < 8; i++) {
driver.findElement(By.id("email")).sendKeys(s.getCell(0,i).getContents());
driver.findElement(By.id("pass")).sendKeys(s.getCell(1,i).getContents());
driver.findElement(By.id("u_0_1")).click();
Thread.sleep(1000);
if (selenium.isElementPresent("id=userNavigationLabel")) {
//driver.findElement(By.cssSelector("span.gb_V.gbii")).click();
driver.findElement(By.id("userNavigationLabel")).click();
driver.findElement(By.cssSelector("input.uiLinkButtonInput")).click();
Thread.sleep(1000);
}
else{
System.out.println("invalid cridential");
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("pass")).clear();
}
}
}
I am not able to find out where the problem is? so how to solve it.
For one thing, don't use "throws Exception" in the method declaration. Instead, have a try block inside the method with a "not null assertion".
Keep in mind that you never want to throw typical exceptions in a test method because it will drop you out of the test lifecycle too early and skip your #After phases. An exception thrown in a #Before annotated method will probably cause a SkipAssertion.
So, what you want to do instead is fail assertions. So, if you have a exception condition that occurs sometimes, swallow the exception (don't throw it) and use an assertion to handle it.
For example:
try {
} catch ( NullPointerException e ) {
Assert.assertTrue( "There was an error in blah.", false );
}
Null pointer means, exepected value of variable is null.
Please check the file exists at the specified path "E:\workspace99\SeleniumAutomations\testdata\LoginData.xls" and you get the value correctly from the file.
The stack trace says the issue is line 31 in your code but your snippet does not allow us to work out where line 31 is .
you are calling "selenium.isElementPresent". Could "selenium" be nil?