Skip to content

Commit 76ce759

Browse files
committed
VRNSKY-18. Fixes from Sonar
1 parent 20d97e7 commit 76ce759

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

chapter10/Mapping/src/main/java/controllers/Adverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
9494
*/
9595
private void fillMapFromParsedRequest(User user, List<FileItem> items) {
9696
for (FileItem item : items) {
97-
log.info("Processing form filed: {}", item.getFieldName());
97+
log.info("Processing form field: {}", sanitizeLogInput(item.getFieldName()));
9898
if (log.isDebugEnabled()) {
9999
String value = item.getString();
100100
value = item.getFieldName().toLowerCase().contains("password") ? "*****" : sanitizeLogInput(value);

chapter9/MusicApp/src/main/java/dao/DaoAddress.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void prepareStatementForInsert(PreparedStatement statement, Address addre
100100
statement.setString(1, address.getCountry());
101101
statement.setString(2, address.getCity());
102102
} catch (SQLException e) {
103-
log.error(e.getMessage(), e);
103+
log.warn(e.getMessage(), e);
104104
}
105105
}
106106

@@ -116,8 +116,7 @@ public void prepareStatementForUpdate(PreparedStatement statement, Address addre
116116
statement.setString(2, address.getCity());
117117
statement.setInt(3, address.getId());
118118
} catch (SQLException e) {
119-
log.error(e.getMessage(), e);
120-
throw new RuntimeException(e.getMessage(), e);
119+
log.warn(e.getMessage(), e);
121120
}
122121
}
123122

@@ -137,8 +136,7 @@ public List<Address> parseResultSet(ResultSet set) {
137136
addresses.add(new Address(id, country, city));
138137
}
139138
} catch (SQLException sqlEx) {
140-
log.error(sqlEx.getMessage(), sqlEx);
141-
throw new RuntimeException(sqlEx.getMessage(), sqlEx);
139+
log.warn(sqlEx.getMessage(), sqlEx);
142140
}
143141
return addresses;
144142
}

chapter9/MusicApp/src/main/java/dao/DaoMusicType.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import org.slf4j.LoggerFactory;
66

77
import java.sql.PreparedStatement;
8-
import java.sql.SQLException;
98
import java.sql.ResultSet;
9+
import java.sql.SQLException;
1010
import java.util.ArrayList;
1111
import java.util.List;
1212

@@ -38,6 +38,7 @@ private DaoMusicType() {
3838

3939
/**
4040
* Return instance of this.
41+
*
4142
* @return instance of this.
4243
*/
4344
public static DaoMusicType getInstance() {
@@ -46,6 +47,7 @@ public static DaoMusicType getInstance() {
4647

4748
/**
4849
* SQL query which select all from table.
50+
*
4951
* @return SQL query for collect all order from concrete table.
5052
*/
5153
@Override
@@ -55,6 +57,7 @@ public String getSelectAll() {
5557

5658
/**
5759
* SQL query which select all data from one row.
60+
*
5861
* @return SQL query for collect data from one row.
5962
*/
6063
@Override
@@ -64,6 +67,7 @@ public String getSelectById() {
6467

6568
/**
6669
* SQL query which edit object at the system.
70+
*
6771
* @return SQL query which edit object in the concrete table.
6872
*/
6973
@Override
@@ -73,6 +77,7 @@ public String getEdit() {
7377

7478
/**
7579
* SQL query which remove order about object from concrete table.
80+
*
7681
* @return SQL query which remove order about object at the concrete table.
7782
*/
7883
@Override
@@ -82,6 +87,7 @@ public String getRemove() {
8287

8388
/**
8489
* SQL query which insert data to the database.
90+
*
8591
* @return SQL INSERT for concrete table.
8692
*/
8793
@Override
@@ -91,37 +97,38 @@ public String getInsert() {
9197

9298
/**
9399
* Set data to the statement.
100+
*
94101
* @param statement instance of PreparedStatement.
95-
* @param object instance of class.
102+
* @param object instance of class.
96103
*/
97104
@Override
98105
public void prepareStatementForInsert(PreparedStatement statement, MusicType object) {
99106
try {
100107
statement.setString(1, object.getType());
101108
} catch (SQLException e) {
102-
log.error(e.getMessage(), e);
103-
throw new RuntimeException("Failed to prepare insert statement", e);
109+
log.warn(e.getMessage(), e);
104110
}
105111
}
106112

107113
/**
108114
* Set data to the statement.
115+
*
109116
* @param statement instance of PreparedStatement.
110-
* @param object instance of class.
117+
* @param object instance of class.
111118
*/
112119
@Override
113120
public void prepareStatementForUpdate(PreparedStatement statement, MusicType object) {
114121
try {
115122
statement.setString(1, object.getType());
116123
statement.setInt(2, object.getId());
117124
} catch (SQLException e) {
118-
log.error(e.getMessage(), e);
119-
throw new RuntimeException("Failed to prepare update statement", e);
125+
log.warn(e.getMessage(), e);
120126
}
121127
}
122128

123129
/**
124130
* Set data to the statement.
131+
*
125132
* @param set instance of result set interface.
126133
* @return list of music types.
127134
*/
@@ -135,8 +142,7 @@ public List<MusicType> parseResultSet(ResultSet set) {
135142
list.add(new MusicType(id, type));
136143
}
137144
} catch (SQLException e) {
138-
log.error(e.getMessage(), e);
139-
throw new RuntimeException("Failed to parse result set", e);
145+
log.warn(e.getMessage(), e);
140146
}
141147

142148
return list;

0 commit comments

Comments
 (0)