From c8b071c89e17bc7c2bb6454905f16a16dc0b50db Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 16 May 2013 14:25:40 +0200 Subject: [PATCH] Fixed BeanPropertyRowMapper to only prefix actual upper-case letters with underscores Issue: SPR-10547 --- .../jdbc/core/BeanPropertyRowMapper.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java index 74dbd6ce7f..c65ac15914 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ import org.springframework.dao.DataRetrievalFailureException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.support.JdbcUtils; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * {@link RowMapper} implementation that converts a row into a new instance @@ -163,18 +164,19 @@ public class BeanPropertyRowMapper implements RowMapper { * @return the converted name */ private String underscoreName(String name) { + if (!StringUtils.hasLength(name)) { + return ""; + } StringBuilder result = new StringBuilder(); - if (name != null && name.length() > 0) { - result.append(name.substring(0, 1).toLowerCase()); - for (int i = 1; i < name.length(); i++) { - String s = name.substring(i, i + 1); - if (s.equals(s.toUpperCase())) { - result.append("_"); - result.append(s.toLowerCase()); - } - else { - result.append(s); - } + result.append(name.substring(0, 1).toLowerCase()); + for (int i = 1; i < name.length(); i++) { + String s = name.substring(i, i + 1); + String slc = s.toLowerCase(); + if (!s.equals(slc)) { + result.append("_").append(slc); + } + else { + result.append(s); } } return result.toString();