[ 
https://issues.apache.org/jira/browse/ARTEMIS-4965?focusedWorklogId=933959&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-933959
 ]

ASF GitHub Bot logged work on ARTEMIS-4965:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 10/Sep/24 10:14
            Start Date: 10/Sep/24 10:14
    Worklog Time Spent: 10m 
      Work Description: gemmellr commented on code in PR #5194:
URL: https://github.com/apache/activemq-artemis/pull/5194#discussion_r1751673939


##########
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:
   Interesting. 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)? If so maybe it passing for you but failing here means its dependent on 
the behaviour of other tests classes, or even the order of tests being run? 
When you say 'locally' do you mean in-IDE, or on CLI (where order should be the 
same, unless particular profiles influence the tests run)? I do see the earlier 
tests in the PR build all look to have their own bespoke Derby shutdown 
handling (some similarly swallowing all exceptions and thus not knowing if they 
got the shutdown-succeeded one)
   
   Presumably also means your shutdown attempt was also failing originally, 
just being swallowed? Which was partly what made me think of using the utility 
method to ensure it wasnt failing. And also as I thought it had more options to 
stop the shutdown deregistering the driver, in case other tests use it later.
   
   Depending on the situation it might be a case of having to swallow the 
failure though, to cover off the alternative of never shutting it down if it is 
later actually registered/used due to code changes?





Issue Time Tracking
-------------------

    Worklog Id:     (was: 933959)
    Time Spent: 1h  (was: 50m)

> 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
>  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


Reply via email to