[
https://issues.apache.org/jira/browse/ARTEMIS-4965?focusedWorklogId=934025&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-934025
]
ASF GitHub Bot logged work on ARTEMIS-4965:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 10/Sep/24 14:21
Start Date: 10/Sep/24 14:21
Worklog Time Spent: 10m
Work Description: jbertram commented on code in PR #5194:
URL: https://github.com/apache/activemq-artemis/pull/5194#discussion_r1752085133
##########
artemis-jdbc-store/src/test/java/org/apache/activemq/artemis/jdbc/store/sql/PropertySQLProviderTest.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.jdbc.store.sql;
+
+import java.sql.DriverManager;
+
+import org.apache.activemq.artemis.tests.util.ArtemisTestCase;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import static
org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider.Factory.SQLDialect.DERBY;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class PropertySQLProviderTest extends ArtemisTestCase {
+
+ @Test
+ public void testGetProperty() {
+ for (SQLProvider.DatabaseStoreType storeType :
SQLProvider.DatabaseStoreType.values()) {
+ PropertySQLProvider factory = (PropertySQLProvider) new
PropertySQLProvider.Factory(DERBY).create("who-cares", storeType);
+ factory.sql("create-file-table");
+ }
+ }
+
+ @Test
+ public void testGetMissingProperty() {
+ for (SQLProvider.DatabaseStoreType storeType :
SQLProvider.DatabaseStoreType.values()) {
+ try {
+ PropertySQLProvider factory = (PropertySQLProvider) new
PropertySQLProvider.Factory(DERBY).create("who-cares", storeType);
+ factory.sql("foo");
+ fail();
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ }
+ }
+
+ @AfterEach
+ public void shutdownDerby() {
+ try {
+ DriverManager.getConnection("jdbc:derby:;shutdown=true");
+ } catch (Exception ignored) {
+ }
Review Comment:
> Doesnt the failure suggest the driver was never registered in the test to
begin with (I just assumed it was, given you added the shutdown step)?
Yes. I originally copied this test from
`org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalLoaderCallbackTest`
which had the `shutdownDerby` method. Apparently this isn't needed at all and
in that test it swallows a similar exception every time. I changed my tests to
use a `null` SQL dialect to make it more clear that Derby isn't required.
Issue Time Tracking
-------------------
Worklog Id: (was: 934025)
Time Spent: 1h 10m (was: 1h)
> Possible null dereference when property is missing in journal-sql.properties
> file
> ---------------------------------------------------------------------------------
>
> Key: ARTEMIS-4965
> URL: https://issues.apache.org/jira/browse/ARTEMIS-4965
> Project: ActiveMQ Artemis
> Issue Type: Bug
> Reporter: Suhov Roman
> Assignee: Justin Bertram
> Priority: Major
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> File:
> https://github.com/apache/activemq-artemis/blob/main/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/PropertySQLProvider.java
> In lines 81,93,94,95,101,106,111,116 and further in the PropertySQLProvider
> class, where properties are received from the journal-sql.properties file, a
> null dereference is possible.
> A dereference can occur if the required property is missing from the
> journal-sql.properties file. A null check must be added to all method return
> values.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact