Commit 734f9f72 by Tuomas Riihimäki

Findbugs fixes. No functional changes

1 parent 1f03debb
Pipeline #10 passed
in 0 seconds
...@@ -23,6 +23,7 @@ import java.util.HashMap; ...@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -92,25 +93,17 @@ public class RestBean implements RestBeanLocal { ...@@ -92,25 +93,17 @@ public class RestBean implements RestBeanLocal {
} }
// Username -> Nonce -> expiration // Username -> Nonce -> expiration
private Map<String, Map<String, Long>> userRestAuths = Collections.synchronizedMap(new HashMap<String, Map<String, Long>>()); private ConcurrentHashMap<String, ConcurrentHashMap<String, Long>> userRestAuths = new ConcurrentHashMap<>();
@Override @Override
public String getLoggedinUserRestNonce() public String getLoggedinUserRestNonce() {
{
String username = context.getCallerPrincipal().getName(); String username = context.getCallerPrincipal().getName();
if (username == null) { if (username == null) {
return null; return null;
} }
Map<String, Long> userAuthMap = userRestAuths.get(username); ConcurrentHashMap<String, Long> userAuthMap = userRestAuths.get(username);
if (userAuthMap == null) { if (userAuthMap == null) {
synchronized (userRestAuths) { userAuthMap = userRestAuths.putIfAbsent(username, new ConcurrentHashMap<>());
if (!userRestAuths.containsKey(username)) {
userAuthMap = Collections.synchronizedMap(new HashMap<String, Long>());
userRestAuths.put(username, userAuthMap);
} else {
userRestAuths.get(username);
}
}
} }
Random random = new Random(); Random random = new Random();
......
...@@ -156,11 +156,11 @@ public class PojoUtils { ...@@ -156,11 +156,11 @@ public class PojoUtils {
public static ReaderEventRestPojo initReaderEventRestPojo(ReaderEvent event) { public static ReaderEventRestPojo initReaderEventRestPojo(ReaderEvent event) {
ReaderEventRestPojo ret = new ReaderEventRestPojo(); ReaderEventRestPojo ret = new ReaderEventRestPojo();
if (event != null && event.getPrintedCard() != null) { if ( event.getPrintedCard() != null) {
if (event.getPrintedCard().getUser() != null) { if (event.getPrintedCard().getUser() != null) {
ret.setEventUser(PojoUtils.initEventUserRestPojo(event.getPrintedCard().getUser())); ret.setEventUser(PojoUtils.initEventUserRestPojo(event.getPrintedCard().getUser()));
} }
} else if (event != null && event.getUser() != null) { } else if (event.getUser() != null) {
ret.setEventUser(PojoUtils.initEventUserRestPojo(event.getUser())); ret.setEventUser(PojoUtils.initEventUserRestPojo(event.getUser()));
} }
...@@ -168,10 +168,10 @@ public class PojoUtils { ...@@ -168,10 +168,10 @@ public class PojoUtils {
ret.setReaderEventTime(event.getUpdatetime()); ret.setReaderEventTime(event.getUpdatetime());
ret.setReaderId(event.getReader().getId()); ret.setReaderId(event.getReader().getId());
if (event != null && event.getPrintedCard() != null) { if (event.getPrintedCard() != null) {
ret.setPrintedCardId(event.getPrintedCard().getId()); ret.setPrintedCardId(event.getPrintedCard().getId());
} }
if (event != null && event.getPrintedCard() != null) { if (event.getPrintedCard() != null) {
ret.setPrintedCardState(event.getPrintedCard().getCardState().name()); ret.setPrintedCardState(event.getPrintedCard().getCardState().name());
} }
return ret; return ret;
......
...@@ -112,7 +112,7 @@ public abstract class GenericImageServlet extends HttpServlet { ...@@ -112,7 +112,7 @@ public abstract class GenericImageServlet extends HttpServlet {
} else { } else {
response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setStatus(HttpServletResponse.SC_NOT_FOUND);
} }
response.getWriter().append("Error " + data.getResponse() + " while fetching data"); response.getWriter().append("Error " + (data == null ? "null-data" : data.getResponse()) + " while fetching data");
} else { } else {
response.setContentLength(data.getData().length); response.setContentLength(data.getData().length);
if (request.getParameter("download") != null) if (request.getParameter("download") != null)
......
...@@ -22,6 +22,7 @@ import java.io.PrintWriter; ...@@ -22,6 +22,7 @@ import java.io.PrintWriter;
import java.io.Serializable; import java.io.Serializable;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import java.util.Map; import java.util.Map;
...@@ -81,7 +82,7 @@ public class ErrorPageView implements Serializable { ...@@ -81,7 +82,7 @@ public class ErrorPageView implements Serializable {
Map<?, ?> requestMap = context.getExternalContext().getRequestMap(); Map<?, ?> requestMap = context.getExternalContext().getRequestMap();
Throwable ex = (Throwable) requestMap.get("javax.servlet.error.exception"); Throwable ex = (Throwable) requestMap.get("javax.servlet.error.exception");
CRC32 stackHash = new CRC32(); CRC32 stackHash = new CRC32();
stackHash.update(Arrays.toString(ex.getStackTrace()).getBytes()); stackHash.update(Arrays.toString(ex.getStackTrace()).getBytes(Charset.forName("UTF-8")));
return "0x" + Long.toHexString(stackHash.getValue()); return "0x" + Long.toHexString(stackHash.getValue());
......
...@@ -94,6 +94,10 @@ public class ImportView extends GenericCDIView { ...@@ -94,6 +94,10 @@ public class ImportView extends GenericCDIView {
} }
} }
if (bytes == null) {
return null;
}
String content = new String(bytes, UTF8); String content = new String(bytes, UTF8);
String[] splittedIds = content.split(";"); String[] splittedIds = content.split(";");
for (String idstr : splittedIds) { for (String idstr : splittedIds) {
......
...@@ -99,7 +99,7 @@ public class UserCartView extends GenericCDIView { ...@@ -99,7 +99,7 @@ public class UserCartView extends GenericCDIView {
sb.append("Added to event").append(CSV_SEPARATOR); sb.append("Added to event").append(CSV_SEPARATOR);
LanEvent event = null; LanEvent event = null;
if (usercart != null && !usercart.isEmpty()) { if (!usercart.isEmpty()) {
event = usercart.get(0).getEvent(); event = usercart.get(0).getEvent();
} }
sb.append("\n"); sb.append("\n");
...@@ -132,12 +132,12 @@ public class UserCartView extends GenericCDIView { ...@@ -132,12 +132,12 @@ public class UserCartView extends GenericCDIView {
if (uc.getCreated() != null) { if (uc.getCreated() != null) {
ul.append(createtimeFormat.format(uc.getCreated().getTime())); ul.append(createtimeFormat.format(uc.getCreated().getTime()));
} }
ul.append(CSV_SEPARATOR); ul.append(CSV_SEPARATOR);
if (uc.getEventuserCreated() != null) { if (uc.getEventuserCreated() != null) {
ul.append(createtimeFormat.format(uc.getEventuserCreated())); ul.append(createtimeFormat.format(uc.getEventuserCreated()));
} }
ul.append(CSV_SEPARATOR); ul.append(CSV_SEPARATOR);
sb.append(ul.toString() sb.append(ul.toString()
...@@ -146,9 +146,6 @@ public class UserCartView extends GenericCDIView { ...@@ -146,9 +146,6 @@ public class UserCartView extends GenericCDIView {
.replaceAll(" ", " ") .replaceAll(" ", " ")
); );
sb.append("\n"); sb.append("\n");
} }
DefaultStreamedContent ret = new DefaultStreamedContent(new ByteArrayInputStream(sb.toString().getBytes(UTF8))); DefaultStreamedContent ret = new DefaultStreamedContent(new ByteArrayInputStream(sb.toString().getBytes(UTF8)));
......
...@@ -36,7 +36,7 @@ import javax.inject.Named; ...@@ -36,7 +36,7 @@ import javax.inject.Named;
@Named @Named
@ConversationScoped @ConversationScoped
public class flowShopView extends GenericCDIView { public class FlowShopView extends GenericCDIView {
private static final long serialVersionUID = 802344850073689859L; private static final long serialVersionUID = 802344850073689859L;
......
...@@ -47,13 +47,9 @@ public class ProductShopItem implements Serializable { ...@@ -47,13 +47,9 @@ public class ProductShopItem implements Serializable {
private Map<ProductOptionGroup, ProductOption> selectedOptions = new HashMap<>(); private Map<ProductOptionGroup, ProductOption> selectedOptions = new HashMap<>();
private BigDecimal overriddenUnitPrice = BigDecimal.ZERO; private BigDecimal overriddenUnitPrice = BigDecimal.ZERO;
private boolean overrideUnitPrice = false; private boolean overrideUnitPrice = false;
public BigDecimal getCreditPrice() public BigDecimal getCreditPrice()
{ {
if (BigDecimal.ZERO.compareTo(price) < 0) if (BigDecimal.ZERO.compareTo(price) < 0)
...@@ -300,19 +296,19 @@ public class ProductShopItem implements Serializable { ...@@ -300,19 +296,19 @@ public class ProductShopItem implements Serializable {
public String getSelectedProductOptionString() { public String getSelectedProductOptionString() {
String retString = ""; StringBuilder retString = new StringBuilder();
for(ProductOption option : this.selectedOptions.values()) { for(ProductOption option : this.selectedOptions.values()) {
if(option == null) if(option == null)
continue; continue;
if(!retString.isEmpty()) { if(retString.length() == 0) {
retString += ", "; retString.append(", ");
} }
retString += option.getName(); retString.append(option.getName());
} }
return retString; return retString.toString();
} }
......
...@@ -60,11 +60,11 @@ public class UserOverviewItem { ...@@ -60,11 +60,11 @@ public class UserOverviewItem {
this.rejectionMsgBody = mailBody; this.rejectionMsgBody = mailBody;
else else
this.rejectionMsgBody = ""; this.rejectionMsgBody = "";
if(this.rejectionMsgSubject.contains("{0}") && eventUser != null && eventUser.getEvent() != null) if(this.rejectionMsgSubject.contains("{0}") && eventUser.getEvent() != null)
this.rejectionMsgSubject = this.rejectionMsgSubject.replace("{0}", eventUser.getEvent().getName()); this.rejectionMsgSubject = this.rejectionMsgSubject.replace("{0}", eventUser.getEvent().getName());
if(this.rejectionMsgBody.contains("{0}") && eventUser != null && eventUser.getEvent() != null) if(this.rejectionMsgBody.contains("{0}") && eventUser.getEvent() != null)
this.rejectionMsgBody = this.rejectionMsgBody.replace("{0}", eventUser.getEvent().getName()); this.rejectionMsgBody = this.rejectionMsgBody.replace("{0}", eventUser.getEvent().getName());
this.rejectionMsgToAddr = eventUser.getEmail(); this.rejectionMsgToAddr = eventUser.getEmail();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!