This is an automated email from the ASF dual-hosted git repository.

harikrishna pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.20 by this push:
     new 6e5d78a8a78 Fix NPE on adding new columns in the tables (#12464)
6e5d78a8a78 is described below

commit 6e5d78a8a78feec31a6dfa893137b65fed5f7677
Author: Harikrishna <[email protected]>
AuthorDate: Thu Jan 22 12:46:16 2026 +0530

    Fix NPE on adding new columns in the tables (#12464)
    
    * Fix NPE on adding new columns in the tables
    
    * Remove assert
---
 .../src/main/java/com/cloud/utils/db/GenericDaoBase.java  | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java 
b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
index 301803aab9b..c3a4d2c2487 100644
--- a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
+++ b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
@@ -89,6 +89,7 @@ import net.sf.cglib.proxy.NoOp;
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Element;
+import org.springframework.util.ClassUtils;
 
 /**
  *  GenericDaoBase is a simple way to implement DAOs.  It DOES NOT
@@ -2047,16 +2048,22 @@ public abstract class GenericDaoBase<T, ID extends 
Serializable> extends Compone
 
     @DB()
     protected void setField(final Object entity, final ResultSet rs, 
ResultSetMetaData meta, final int index) throws SQLException {
-        Attribute attr = _allColumns.get(new Pair<String, 
String>(meta.getTableName(index), meta.getColumnName(index)));
+        String tableName = meta.getTableName(index);
+        String columnName = meta.getColumnName(index);
+        Attribute attr = _allColumns.get(new Pair<>(tableName, columnName));
         if (attr == null) {
             // work around for mysql bug to return original table name instead 
of view name in db view case
             Table tbl = 
entity.getClass().getSuperclass().getAnnotation(Table.class);
             if (tbl != null) {
-                attr = _allColumns.get(new Pair<String, String>(tbl.name(), 
meta.getColumnLabel(index)));
+                attr = _allColumns.get(new Pair<>(tbl.name(), 
meta.getColumnLabel(index)));
             }
         }
-        assert (attr != null) : "How come I can't find " + 
meta.getCatalogName(index) + "." + meta.getColumnName(index);
-        setField(entity, attr.field, rs, index);
+        if(attr == null) {
+            logger.warn(String.format("Failed to find attribute in the entity 
%s to map column %s.%s (%s)",
+                    ClassUtils.getUserClass(entity).getSimpleName(), 
tableName, columnName));
+        } else {
+            setField(entity, attr.field, rs, index);
+        }
     }
 
     @Override

Reply via email to