Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323188 - field access cause NullPointerException
Summary: field access cause NullPointerException
Status: CLOSED WONTFIX
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-19 15:43 EDT by nossie531 CLA
Modified: 2022-06-09 10:24 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nossie531 CLA 2010-08-19 15:43:46 EDT
Build Identifier: 

Sorry I'm not good at English...

But I noticed very strange behavior at EclipseLink.
If compare EntityBean field(null) to null, cause NullPointerException.
(if compare EntityBean field(null) to other, cause no exception.)
And strangely this NullPointerException's stackTrace is null!

Uhh... because of bytecode conversion or dynamic weaving???

My enviroments are follows;
EclipseLink: nightly 2.2.0(2010/8/19)r8063 
Server: Glassfish v3.0.1
JDBC connector:mysql-connector-java-5.1.3-rc-bin.jar
IDE: Eclipse Helios

Reproducible: Always

Steps to Reproduce:
1. create database "test" and run sql.
CREATE TABLE test (
	id INTEGER NOT NULL AUTO_INCREMENT,
	value INTEGER DEFAULT NULL,
	PRIMARY KEY(id)
) ENGINE = INNODB;

INSERT INTO test ( 
	id, value
) VALUES (
	1, NULL
);

2. TestEntityBean.java
package jpa;

import java.io.Serializable;

import javax.persistence.*;

@Entity
@Table(schema="test", name="test")
public class TestEntityBean implements Serializable {

	private static final long serialVersionUID = 7100714529417828468L;
	
	@Id
	@Column(name = "id", nullable = false)
	private int id;
	@Column(name="value")
	private Integer value;
	
	public TestEntityBean() {
		super();
	}
	
	public boolean test() {
		// OK.
		// return this.value != null?true:false;
		
		// NG. NullPointerException !!
		return this.value != 1?true:false;
	}
	
}

3. TestManagedBean.java
package jsf;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import jpa.TestEntityBean;

@ManagedBean(name="test")
@RequestScoped
public class TestManagedBean {
	
    @PersistenceContext(unitName="test")
    private EntityManager em;
	
	public void test() {
		TestEntityBean test = em.find(TestEntityBean.class, 1);
		test.test();
	}
	
}

4. test.xhtml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:my="http://www.test.com/tag.taglib.xml">
<head>
<title>test</title>
</head>
<body>
	<f:view>
		<h:form>
			<h:commandButton action="#{test.test}"/>
		</h:form>
	</f:view>
</body>
</html>

5.persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 
	xmlns="http://java.sun.com/xml/ns/persistence"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
	<persistence-unit name="test" transaction-type="JTA">
		<provider>
			org.eclipse.persistence.jpa.PersistenceProvider
		</provider>
		<jta-data-source>jdbc/MySql</jta-data-source>
		<properties>
			<property name="eclipselink.logging.level" value="Fine" />
		</properties>
	</persistence-unit>
</persistence>
Comment 1 Tom Ware CLA 2010-08-19 15:54:44 EDT
I suspect this is related to the fact that you are expecting autoboxing to work on the followings statement:

      return this.value != 1?true:false;

You expect "1" to be autoboxed to an Integer.  It is possible that our bytecode weaving will defeat that assumption.

Does return this.value != Integer.valueOf(1)?true:false; solve the problem?

Closing as WONTFIX.
Comment 2 nossie531 CLA 2010-08-19 16:11:44 EDT
Oh!! work fine! Thank you!!
And I'm sorry I post wrong!!
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:24:20 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink