Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C1970200AE4 for ; Fri, 10 Jun 2016 03:52:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C030F160A59; Fri, 10 Jun 2016 01:52:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E112E160A58 for ; Fri, 10 Jun 2016 03:52:13 +0200 (CEST) Received: (qmail 54483 invoked by uid 500); 10 Jun 2016 01:52:13 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 54474 invoked by uid 99); 10 Jun 2016 01:52:13 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Jun 2016 01:52:13 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 99BEEC0E1A for ; Fri, 10 Jun 2016 01:52:12 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.374 X-Spam-Level: X-Spam-Status: No, score=0.374 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 1ulo2PNC3fqR for ; Fri, 10 Jun 2016 01:52:11 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 4EF1D5F1D5 for ; Fri, 10 Jun 2016 01:52:10 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 69E39E0BBD for ; Fri, 10 Jun 2016 01:52:09 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 4CC303A0287 for ; Fri, 10 Jun 2016 01:52:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1747621 - in /poi/branches/xssf_structured_references/src: java/org/apache/poi/hssf/usermodel/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/ Date: Fri, 10 Jun 2016 01:52:08 -0000 To: commits@poi.apache.org From: onealj@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160610015209.4CC303A0287@svn01-us-west.apache.org> archived-at: Fri, 10 Jun 2016 01:52:14 -0000 Author: onealj Date: Fri Jun 10 01:52:08 2016 New Revision: 1747621 URL: http://svn.apache.org/viewvc?rev=1747621&view=rev Log: bug 57840: check for null to avoid NPE; add unit test for XSSFWorkbook.getTable() Modified: poi/branches/xssf_structured_references/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java poi/branches/xssf_structured_references/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java poi/branches/xssf_structured_references/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java poi/branches/xssf_structured_references/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java poi/branches/xssf_structured_references/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Modified: poi/branches/xssf_structured_references/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java URL: http://svn.apache.org/viewvc/poi/branches/xssf_structured_references/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java?rev=1747621&r1=1747620&r2=1747621&view=diff ============================================================================== --- poi/branches/xssf_structured_references/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java (original) +++ poi/branches/xssf_structured_references/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java Fri Jun 10 01:52:08 2016 @@ -265,10 +265,15 @@ public final class HSSFEvaluationWorkboo return extIx; } + @Override public SpreadsheetVersion getSpreadsheetVersion(){ return SpreadsheetVersion.EXCEL97; } + /** + * @throws IllegalStateException: data tables are not supported in Excel 97-2003 format + */ + @Override public Table getTable(String name) { throw new IllegalStateException("XSSF-style tables are not supported for HSSF"); } Modified: poi/branches/xssf_structured_references/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java URL: http://svn.apache.org/viewvc/poi/branches/xssf_structured_references/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java?rev=1747621&r1=1747620&r2=1747621&view=diff ============================================================================== --- poi/branches/xssf_structured_references/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java (original) +++ poi/branches/xssf_structured_references/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java Fri Jun 10 01:52:08 2016 @@ -353,8 +353,11 @@ public abstract class BaseXSSFEvaluation * @return The Data table in the workbook named name, or null if no table is named name. * @since 3.15 beta 2 */ + @Override public XSSFTable getTable(String name) { - return getTableCache().get(name.toLowerCase(Locale.ROOT)); + if (name == null) return null; + String lname = name.toLowerCase(Locale.ROOT); + return getTableCache().get(lname); } public UDFFinder getUDFFinder(){ Modified: poi/branches/xssf_structured_references/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java URL: http://svn.apache.org/viewvc/poi/branches/xssf_structured_references/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1747621&r1=1747620&r2=1747621&view=diff ============================================================================== --- poi/branches/xssf_structured_references/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original) +++ poi/branches/xssf_structured_references/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Fri Jun 10 01:52:08 2016 @@ -2271,7 +2271,7 @@ public class XSSFWorkbook extends POIXML * @since 3.15 beta 2 */ public XSSFTable getTable(String name) { - if (sheets != null) { + if (name != null && sheets != null) { for (XSSFSheet sheet : sheets) { for (XSSFTable tbl : sheet.getTables()) { if (name.equalsIgnoreCase(tbl.getName())) { Modified: poi/branches/xssf_structured_references/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java URL: http://svn.apache.org/viewvc/poi/branches/xssf_structured_references/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=1747621&r1=1747620&r2=1747621&view=diff ============================================================================== --- poi/branches/xssf_structured_references/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original) +++ poi/branches/xssf_structured_references/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Fri Jun 10 01:52:08 2016 @@ -1137,7 +1137,7 @@ public final class TestXSSFSheet extends } /** - * See bug #50829 + * See bug #50829 test data tables */ @Test public void tables() throws IOException { Modified: poi/branches/xssf_structured_references/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java URL: http://svn.apache.org/viewvc/poi/branches/xssf_structured_references/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=1747621&r1=1747620&r2=1747621&view=diff ============================================================================== --- poi/branches/xssf_structured_references/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original) +++ poi/branches/xssf_structured_references/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Fri Jun 10 01:52:08 2016 @@ -1107,4 +1107,36 @@ public final class TestXSSFWorkbook exte assertTrue("Had: " + e.getCause(), e.getCause() instanceof IOException); } } + + /** + * See bug #57840 test data tables + */ + @Test + public void getTable() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithTable.xlsx"); + XSSFTable table1 = wb.getTable("Tabella1"); + assertNotNull("Tabella1 was not found in workbook", table1); + assertEquals("Table name", "Tabella1", table1.getName()); + assertEquals("Sheet name", "Foglio1", table1.getSheetName()); + + // Table lookup should be case-insensitive + assertSame("Case insensitive table name lookup", table1, wb.getTable("TABELLA1")); + + // If workbook does not contain any data tables matching the provided name, getTable should return null + assertNull("Null table name should not throw NPE", wb.getTable(null)); + assertNull("Should not be able to find non-existent table", wb.getTable("Foglio1")); + + // If a table is added after getTable is called it should still be reachable by XSSFWorkbook.getTable + // This test makes sure that if any caching is done that getTable never uses a stale cache + XSSFTable table2 = wb.getSheet("Foglio2").createTable(); + table2.setName("Table2"); + assertSame("Did not find Table2", table2, wb.getTable("Table2")); + + // If table name is modified after getTable is called, the table can only be found by its new name + // This test makes sure that if any caching is done that getTable never uses a stale cache + table1.setName("Table1"); + assertSame("Did not find Tabella1 renamed to Table1", table1, wb.getTable("TABLE1")); + + wb.close(); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org