Exception Posts

A Weird Exception, java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name “FilterName”

Today i found an exception while deploying my .war application to Tomcat web server for production usage, very weird because i never had this exception on my IDE before. This is the complete exception stacktrace,

Caused by: java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name FilterName
	at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:2506)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)

below is my web.xml content,

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="crm" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd">
    <display-name>edw</display-name>
    <context-param>
        <param-name>edw</param-name>
        <param-value>edw</param-value>
    </context-param>
    
    <filter-mapping>
        <filter-name>FilterName</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
	
    <filter>
        <filter-name>FilterName</filter-name>
        <filter-class>com.edw.filter.FilterName</filter-class>
    </filter>
</web-app>

How to fix it is actually very simple, i only need to swap between and tag. Below is the correct web.xml.

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="crm" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd">
    <display-name>edw</display-name>
    <context-param>
        <param-name>edw</param-name>
        <param-value>edw</param-value>
    </context-param>
    
    <filter>
        <filter-name>FilterName</filter-name>
        <filter-class>com.edw.filter.FilterName</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>FilterName</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

Weird eh :p

Google+

A Weird Exception When Using Java’s BigDecimal, java.lang.ArithmeticException: Rounding necessary

I found this weird exception when im trying to convert double values to BigDecimal,

java.lang.ArithmeticException: Rounding necessary
	at java.math.BigDecimal.divideAndRound(BigDecimal.java:1439)
	at java.math.BigDecimal.setScale(BigDecimal.java:2394)
	at java.math.BigDecimal.setScale(BigDecimal.java:2437)

This is my java code

BigDecimal bgAvg = new BigDecimal(0);
bgAvg = bgAvg.add(new BigDecimal(myDoubleValue).setScale(2));

Somehow the error is gone after i changed my code into this

BigDecimal bgAvg = new BigDecimal(0);
bgAvg = bgAvg.add(BigDecimal.valueOf(myDoubleValue).setScale(2));

Hope it helped others, have fun with Java ;)

Google+

NullPointerException When Using JPA

I got this weird error while trying to select a data using Eclipselink JPA on my Glassfish AppServer

[#|2012-02-02T00:47:09.746+0700|SEVERE| glassfish3.0.1|javax.enterprise.system.std.com.sun. enterprise.v3. services.impl|_ThreadID=31;_ThreadName=http-thread-pool-8080-(1);| java.lang.NullPointerException
	at com.edw.xxx.dto.Account._persistence_set(Account.java)

here is the complete details of my error

[#|2012-02-02T00:47:09.746+0700|SEVERE|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3. services.impl|_ThreadID=31;_ThreadName=http-thread-pool-8080-(1);| java.lang.NullPointerException
	at com.edw.xxx.dto.Account._persistence_set(Account.java)
	at org.eclipse.persistence.internal.descriptors.PersistenceObjectAttributeAccessor. setAttributeValueInObject(PersistenceObjectAttributeAccessor.java:46)
	at org.eclipse.persistence.mappings.DatabaseMapping. setAttributeValueInObject(DatabaseMapping.java:1367)
	at org.eclipse.persistence.mappings.DatabaseMapping. readFromRowIntoObject(DatabaseMapping.java:1258)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildAttributesIntoObject(ObjectBuilder.java:331)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObject(ObjectBuilder.java:660)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildWorkingCopyCloneNormally(ObjectBuilder.java:582)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObjectInUnitOfWork(ObjectBuilder.java:551)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObject(ObjectBuilder.java:491)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObject(ObjectBuilder.java:443)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery. buildObject(ObjectLevelReadQuery.java:635)
	at org.eclipse.persistence.queries.ReadAllQuery.registerResultInUnitOfWork(ReadAllQuery.java:838)
	at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:464)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:997)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:958)
	at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:432)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1021)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2857)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1181)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:453)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:714)

And here is the code for my Account.java

@Entity
@Table(name = "account")
@XmlRootElement
@NamedQueries({ 
    @NamedQuery(name = "Account.findAll", query = "SELECT a FROM Account a")
    })
public class Account implements Serializable {
    
    private static final long serialVersionUID = 1L;
	
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "acc_no")
    private Long accNo;
	
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
	
    @Basic(optional = false)
    @Column(name = "pwd")
    private String pwd;
	
    @Basic(optional = false)
    @Column(name = "gender")
    private char gender;	

    public Account() {
    }

    // other setters and getters   
}

Actually, the main suspect here is the attribute “gender”. It shows NullPointerException due to “gender” is a basic type ( char ) while the row “gender” in database is null.

(&amp;) Weird isnt it?

Google+

InvalidClassException: com.sun.rowset.providers. RIOptimisticProvider; local class incompatible: stream classdesc serialVersionUID

i ran into this weird exception when im trying to connecting a Swing Application + Crystal Report to a database via EJB. I dont know why, but this error always happen only at reporting module. And what makes it weird that this exception only happen at several terminals only.

java.rmi.RemoteException: null; nested exception is: 
	java.io.InvalidClassException: com.sun.rowset.providers.RIOptimisticProvider; local class incompatible: stream classdesc serialVersionUID = -3143367176751761936, local class serialVersionUID = -8429279896237029122
	at com.rubean.statelesstunnel.client.BusinessInterfaceProxyFactory$Handler.invoke(Unknown Source)
	at $Proxy7.runNamedReportQuery(Unknown Source)
	at com.xxx.GenericQueryDelegate.runnamedReportQuery(ReportQueryDelegate.java:166)
	at com.xxx.report.RptOne.setQuery(RptOne.java:78)
	at com.xxx.report.RptOne$runReport.run(RptOne.java:136)
Caused by: java.io.InvalidClassException: com.sun.rowset.providers.RIOptimisticProvider; local class incompatible: stream classdesc serialVersionUID = -3143367176751761936, local class serialVersionUID = -8429279896237029122
	at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:562)
	at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1583)
	at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
	at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
	at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
	at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
	at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
	at com.rubean.statelesstunnel.client.http.HttpRequestorCompression.postRequest(HttpRequestorCompression.java:60)
	... 5 more
	

after some research i found out that this exception happen only to terminals using JRE 1.60 update 7 or less.

C:\Users\edw>java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

this exception gone after i updated every terminal’s JRE into JRE 1.60 update 19

C:\Users\edw>java -version
java version "1.6.0_19"
Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
Java HotSpot(TM) Client VM (build 16.2-b04, mixed mode, sharing)

And now i have to update every terminals that are still using JRE 1.6.0_07. Weird eh, hahahaa…..

Google+