Return-Path: X-Original-To: apmail-openjpa-dev-archive@www.apache.org Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AF43A11B88 for ; Tue, 3 Jun 2014 10:52:01 +0000 (UTC) Received: (qmail 91250 invoked by uid 500); 3 Jun 2014 10:52:01 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 91206 invoked by uid 500); 3 Jun 2014 10:52:01 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 91195 invoked by uid 99); 3 Jun 2014 10:52:01 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jun 2014 10:52:01 +0000 Date: Tue, 3 Jun 2014 10:52:01 +0000 (UTC) From: "David Bilge (JIRA)" To: dev@openjpa.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (OPENJPA-2507) Weird EmptyStackException in CriteriaQueryImpl MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/OPENJPA-2507?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14016377#comment-14016377 ] David Bilge edited comment on OPENJPA-2507 at 6/3/14 10:50 AM: --------------------------------------------------------------- I experienced this very bug and created a demo project (see attached {{openjpa-exception-demo.zip}}) - if that helps. Just execute {{LoadTest#parallelTest}} and invariably one of the exceptions in {{exceptions.txt}} will be thrown. One of those is the {{EmptyStackException}}. It is easy to reproduce this without Spring Data by using this alternative implementation for the {{DemoRepository}} interface from the demo project: {code:java} @Component public class ManualDemoRepository implements DemoRepository { @Autowired EntityManager entityManager; CriteriaQuery criteriaQuery; @PostConstruct public void initQuery() { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); criteriaQuery = criteriaBuilder.createQuery(DemoEntity.class); Root demoRoot = criteriaQuery.from(DemoEntity.class); criteriaQuery.select(demoRoot).where(criteriaBuilder.equal(demoRoot.get(DemoEntity_.demoNumber), 42)); } @Override public DemoEntity findByDemoNumber(int demoNumber) { return entityManager.createQuery(criteriaQuery).getSingleResult(); } } {code} was (Author: viadavid): I experienced this very bug and created a demo project - if that helps. Just execute {{LoadTest#parallelTest}} and invariably one of the exceptions in {{exceptions.txt}} will be thrown. One of those is the {{EmptyStackException}}. It is easy to reproduce this without Spring Data by using this alternative implementation for the {{DemoRepository}} interface from the demo project: {code:java} @Component public class ManualDemoRepository implements DemoRepository { @Autowired EntityManager entityManager; CriteriaQuery criteriaQuery; @PostConstruct public void initQuery() { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); criteriaQuery = criteriaBuilder.createQuery(DemoEntity.class); Root demoRoot = criteriaQuery.from(DemoEntity.class); criteriaQuery.select(demoRoot).where(criteriaBuilder.equal(demoRoot.get(DemoEntity_.demoNumber), 42)); } @Override public DemoEntity findByDemoNumber(int demoNumber) { return entityManager.createQuery(criteriaQuery).getSingleResult(); } } {code} > Weird EmptyStackException in CriteriaQueryImpl > ---------------------------------------------- > > Key: OPENJPA-2507 > URL: https://issues.apache.org/jira/browse/OPENJPA-2507 > Project: OpenJPA > Issue Type: Bug > Components: criteria > Affects Versions: 2.2.0, 2.3.0 > Environment: openjpa 2.2.0 & 2.3.0, spring-data-jpa up to 1.4.2 > Reporter: Ioannis Alexandrakis > Priority: Minor > Labels: criteria_api, openjpa > Attachments: exceptions.txt, openjpa-exception-demo.zip > > > Using spring-data-jpa with openjpa, I sometimes encounter a strange error (not all the times, but under heavy load it makes its appearance, sparsely though): > .... > Caused by: java.util.EmptyStackException > at java.util.Stack.peek(Stack.java:) > at org.apache.openjpa.persistence.criteria.CriteriaQueryImpl.ctx(CriteriaQueryImpl.java: > .... > I do not know which behaviour triggers it, however I think it would be an improvement to change (I did not know where exactly to file it, because it is both an improvement and a bug in my opinion), in org.apache.openjpa.persistence.criteria.CriteriaQueryImpl, method: Context ctx(), this: > return _contexts == null || _contexts.isEmpty() ? null : _contexts.peek(); > to something like this: > try { > return _contexts == null || _contexts.isEmpty() ? null : _contexts.peek(); > } catch (EmptyStackException e) { > return null; > } > , in order to prevent a case where multiple threads modify the "_contexts" between the evaluation of the inline "if". > I am not able to reproduce it all the time, thus I can't create a useful test, neither have I created a patch due to the simplicity of the 'fix'. However I believe it is a harmless fix which could be considered a minor improvement. -- This message was sent by Atlassian JIRA (v6.2#6252)