채수원 2015-03-12
Merge branch 'fix/by-idea-and-findbugs' into 'next'
from pull-request 1493

* refs/heads/fix/by-idea-and-findbugs:
  Organize imports of classes in models package
  Remove unused method
  Fix unnecessary boxing/unboxing
  Implements Cloneable if defines clone()
  Make fields final if possible
  Make availableStates immutable
  Update FastHttpDateFormat to fix thread-safe bug
  Cleanup unnecessary code
  Fix reliance on default encoding
  Fix possible NPE
  Fix possible NPE
  Add missed assignments
  Fix incorrect comparision
  Property: Make sure check() returns nonnull list
  Fix incorrect string format
  Remove redundant null-check
  Rename merger to mergeResult
  Remove redundant codes
  Fix possible NPE of rm_rf()
  Remove redundant null-check

Reviewed-by: 채수원 
@ca48c652c47ae42947aaeb4eaf5ee11b3156db1c
app/Global.java
--- app/Global.java
+++ app/Global.java
@@ -162,14 +162,14 @@
             }
 
             private void replaceSiteSecretKey(String seed) throws IOException {
-                SecureRandom random = new SecureRandom(seed.getBytes());
+                SecureRandom random = new SecureRandom(seed.getBytes(Config.getCharset()));
                 String secret = new BigInteger(130, random).toString(32);
 
                 Path path = Paths.get("conf/application.conf");
                 byte[] bytes = Files.readAllBytes(path);
-                String config = new String(bytes);
+                String config = new String(bytes, Config.getCharset());
                 config = config.replace(DEFAULT_SECRET, secret);
-                Files.write(path, config.getBytes());
+                Files.write(path, config.getBytes(Config.getCharset()));
             }
 
             private boolean hasError(Form<User> newUserForm) {
app/controllers/BoardApp.java
--- app/controllers/BoardApp.java
+++ app/controllers/BoardApp.java
@@ -55,6 +55,7 @@
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Objects;
 
 import static com.avaje.ebean.Expr.icontains;
 
@@ -244,7 +245,7 @@
 
     private static void unmarkAnotherReadmePostingIfExists(Project project, Long postingNumber) {
         Posting previousReadmePosting = Posting.findREADMEPosting(project);
-        if(previousReadmePosting != null && previousReadmePosting.getNumber() != postingNumber){
+        if(previousReadmePosting != null && !Objects.equals(previousReadmePosting.getNumber(), postingNumber)){
             previousReadmePosting.readme = false;
             previousReadmePosting.directSave();
         }
app/controllers/CodeHistoryApp.java
--- app/controllers/CodeHistoryApp.java
+++ app/controllers/CodeHistoryApp.java
@@ -98,7 +98,7 @@
         Project project = Project.findByOwnerAndProjectName(ownerName, projectName);
         PlayRepository repository = RepositoryService.getRepository(project);
 
-        Commit commit = null;
+        Commit commit;
 
         try {
             commit = repository.getCommit(commitId);
app/controllers/ImportApp.java
--- app/controllers/ImportApp.java
+++ app/controllers/ImportApp.java
@@ -42,6 +42,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.List;
+import java.util.Objects;
 
 import static play.data.Form.form;
 
@@ -57,7 +58,7 @@
     }
 
     @Transactional
-    public static Result newProject() throws GitAPIException, IOException {
+    public static Result newProject() throws Exception {
         if( !AccessControl.isGlobalResourceCreatable(UserApp.currentUser()) ){
             return forbidden("'" + UserApp.currentUser().name + "' has no permission");
         }
@@ -180,7 +181,7 @@
             result = badRequest(create.render("title.newProject", newProjectForm, orgUserList));
         }
 
-        if (ownerIsUser && UserApp.currentUser().id != user.id) {
+        if (ownerIsUser && !Objects.equals(UserApp.currentUser().id, user.id)) {
             newProjectForm.reject("owner", "project.owner.invalidate");
             hasError = true;
             result = badRequest(create.render("title.newProject", newProjectForm, orgUserList));
app/controllers/IssueApp.java
--- app/controllers/IssueApp.java
+++ app/controllers/IssueApp.java
@@ -75,9 +75,6 @@
         Page<Issue> issues = el.findPagingList(itemsPerPage).getPage(searchCondition.pageNum);
 
         switch(format){
-            case EXCEL_EXT:
-                return issuesAsExcel(project, el);
-
             case "pjax":
                 return issuesAsPjax(project, issues, searchCondition);
 
@@ -312,7 +309,7 @@
                 if(hasAssignee(issue)) {
                     oldAssignee = issue.assignee.user;
                 }
-                Assignee newAssignee = null;
+                Assignee newAssignee;
                 if (issueMassUpdate.assignee.isAnonymous()) {
                     newAssignee = null;
                 } else {
app/controllers/PullRequestApp.java
--- app/controllers/PullRequestApp.java
+++ app/controllers/PullRequestApp.java
@@ -654,7 +654,7 @@
 
     }
 
-    public static class SearchCondition {
+    public static class SearchCondition implements Cloneable {
         public Project project;
         public String filter;
         public Long contributorId;
app/models/AbstractPosting.java
--- app/models/AbstractPosting.java
+++ app/models/AbstractPosting.java
@@ -23,11 +23,11 @@
 import models.enumeration.ResourceType;
 import models.resource.Resource;
 import models.resource.ResourceConvertible;
-
 import org.joda.time.Duration;
 import play.data.format.Formats;
 import play.data.validation.Constraints;
-import play.db.ebean.*;
+import play.db.ebean.Model;
+import play.db.ebean.Transactional;
 import utils.JodaDateUtil;
 
 import javax.persistence.*;
app/models/Assignee.java
--- app/models/Assignee.java
+++ app/models/Assignee.java
@@ -20,16 +20,14 @@
  */
 package models;
 
-import java.util.Set;
+import play.data.validation.Constraints.Required;
+import play.db.ebean.Model;
 
-import javax.persistence.CascadeType;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.ManyToOne;
 import javax.persistence.OneToMany;
-
-import play.data.validation.Constraints.Required;
-import play.db.ebean.Model;
+import java.util.Set;
 
 @Entity
 public class Assignee extends Model {
app/models/Attachment.java
--- app/models/Attachment.java
+++ app/models/Attachment.java
@@ -20,7 +20,6 @@
  */
 package models;
 
-import utils.AttachmentCache;
 import controllers.AttachmentApp;
 import models.enumeration.ResourceType;
 import models.resource.GlobalResource;
@@ -33,6 +32,7 @@
 import play.db.ebean.Model;
 import play.libs.Akka;
 import scala.concurrent.duration.Duration;
+import utils.AttachmentCache;
 import utils.FileUtil;
 import utils.JodaDateUtil;
 
app/models/AuthInfo.java
--- app/models/AuthInfo.java
+++ app/models/AuthInfo.java
@@ -21,7 +21,6 @@
 package models;
 
 import play.data.validation.Constraints;
-import utils.ReservedWordsValidator;
 
 public class AuthInfo {
     @Constraints.Required
app/models/Issue.java
--- app/models/Issue.java
+++ app/models/Issue.java
@@ -35,6 +35,7 @@
 import models.resource.Resource;
 import models.support.SearchCondition;
 import org.apache.commons.lang3.time.DateUtils;
+import org.apache.shiro.util.CollectionUtils;
 import play.data.Form;
 import play.data.format.Formats;
 import play.i18n.Messages;
@@ -68,11 +69,8 @@
     @Formats.DateTime(pattern = "yyyy-MM-dd")
     public Date dueDate;
 
-    public static List<State> availableStates = new ArrayList<>();
-    static {
-        availableStates.add(State.OPEN);
-        availableStates.add(State.CLOSED);
-    }
+    public static final List<State> availableStates =
+            Collections.unmodifiableList(CollectionUtils.asList(State.OPEN, State.CLOSED));
 
     @ManyToOne
     public Milestone milestone;
@@ -371,7 +369,7 @@
             return otherAssignee == null || otherAssignee.user == null || otherAssignee.user.isAnonymous();
         }
         if (otherAssignee == null || otherAssignee.user == null || otherAssignee.user.isAnonymous()) {
-            return assignee == null || assignee.user == null || assignee.user.isAnonymous();
+            return assignee.user.isAnonymous();
         }
         return assignee.equals(otherAssignee) || assignee.user.equals(otherAssignee.user);
     }
app/models/IssueComment.java
--- app/models/IssueComment.java
+++ app/models/IssueComment.java
@@ -30,7 +30,7 @@
 @Entity
 public class IssueComment extends Comment {
     private static final long serialVersionUID = 1L;
-    public static Finder<Long, IssueComment> find = new Finder<>(Long.class, IssueComment.class);
+    public static final Finder<Long, IssueComment> find = new Finder<>(Long.class, IssueComment.class);
 
     @ManyToOne
     public Issue issue;
app/models/IssueEvent.java
--- app/models/IssueEvent.java
+++ app/models/IssueEvent.java
@@ -27,7 +27,9 @@
 import play.db.ebean.Model;
 
 import javax.persistence.*;
-import java.util.*;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.regex.Matcher;
 
 @Entity
@@ -55,7 +57,7 @@
     private static final int DRAFT_TIME_IN_MILLIS = Configuration.root()
         .getMilliseconds("application.issue-event.draft-time", 30 * 1000L).intValue();
 
-    public static Finder<Long, IssueEvent> find = new Finder<>(Long.class,
+    public static final Finder<Long, IssueEvent> find = new Finder<>(Long.class,
             IssueEvent.class);
 
     /**
app/models/IssueLabelCategory.java
--- app/models/IssueLabelCategory.java
+++ app/models/IssueLabelCategory.java
@@ -21,10 +21,10 @@
 package models;
 
 import models.enumeration.ResourceType;
-import play.db.ebean.Model;
 import models.resource.Resource;
 import models.resource.ResourceConvertible;
 import play.data.validation.Constraints.Required;
+import play.db.ebean.Model;
 
 import javax.persistence.*;
 import javax.validation.constraints.Size;
app/models/LabelOwner.java
--- app/models/LabelOwner.java
+++ app/models/LabelOwner.java
@@ -20,10 +20,10 @@
  */
 package models;
 
-import java.util.Set;
-
 import models.resource.ResourceConvertible;
 
+import java.util.Set;
+
 /**
  * @see models.resource.ResourceConvertible
  */
app/models/Milestone.java
--- app/models/Milestone.java
+++ app/models/Milestone.java
@@ -20,20 +20,24 @@
  */
 package models;
 
-import models.enumeration.*;
+import models.enumeration.Direction;
+import models.enumeration.Matching;
+import models.enumeration.ResourceType;
+import models.enumeration.State;
 import models.resource.Resource;
 import models.resource.ResourceConvertible;
-import models.support.*;
-
+import models.support.FinderTemplate;
+import models.support.OrderParams;
+import models.support.SearchParams;
 import org.apache.commons.lang3.time.DateUtils;
-import play.data.format.*;
-import play.data.validation.*;
-import play.db.ebean.*;
+import play.data.format.Formats;
+import play.data.validation.Constraints;
+import play.db.ebean.Model;
 import play.i18n.Messages;
 import utils.JodaDateUtil;
 
 import javax.persistence.*;
-import java.text.*;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 @Entity
app/models/NonRangedCodeCommentThread.java
--- app/models/NonRangedCodeCommentThread.java
+++ app/models/NonRangedCodeCommentThread.java
@@ -20,9 +20,10 @@
  */
 package models;
 
+import org.apache.commons.lang3.StringUtils;
+
 import javax.persistence.DiscriminatorValue;
 import javax.persistence.Entity;
-import org.apache.commons.lang3.StringUtils;
 
 /**
  * @author Keesun Baik
app/models/NotificationEvent.java
--- app/models/NotificationEvent.java
+++ app/models/NotificationEvent.java
@@ -20,7 +20,6 @@
  */
 package models;
 
-import com.avaje.ebean.RawSql;
 import com.avaje.ebean.RawSqlBuilder;
 import controllers.UserApp;
 import controllers.routes;
@@ -42,7 +41,6 @@
 import playRepository.*;
 import scala.concurrent.duration.Duration;
 import utils.AccessControl;
-import utils.Config;
 import utils.EventConstants;
 import utils.RouteUtil;
 
@@ -52,7 +50,10 @@
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
-import java.util.*;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -66,7 +67,7 @@
     @Id
     public Long id;
 
-    public static Finder<Long, NotificationEvent> find = new Finder<>(Long.class, NotificationEvent.class);
+    public static final Finder<Long, NotificationEvent> find = new Finder<>(Long.class, NotificationEvent.class);
 
     public String title;
 
app/models/NotificationMail.java
--- app/models/NotificationMail.java
+++ app/models/NotificationMail.java
@@ -20,8 +20,8 @@
  */
 package models;
 
-import mailbox.EmailAddressWithDetail;
 import info.schleichardt.play2.mailplugin.Mailer;
+import mailbox.EmailAddressWithDetail;
 import models.enumeration.ResourceType;
 import models.enumeration.UserState;
 import models.resource.Resource;
@@ -43,11 +43,11 @@
 import utils.Markdown;
 import utils.Url;
 
+import javax.annotation.Nullable;
 import javax.mail.MessagingException;
 import javax.mail.Session;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
-import javax.annotation.Nullable;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.OneToOne;
@@ -69,7 +69,7 @@
     @OneToOne
     public NotificationEvent notificationEvent;
 
-    public static Finder<Long, NotificationMail> find = new Finder<>(Long.class,
+    public static final Finder<Long, NotificationMail> find = new Finder<>(Long.class,
             NotificationMail.class);
 
     public static void onStart() {
app/models/OrganizationUser.java
--- app/models/OrganizationUser.java
+++ app/models/OrganizationUser.java
@@ -20,14 +20,13 @@
  */
 package models;
 
-import java.util.List;
+import models.enumeration.RoleType;
+import play.db.ebean.Model;
 
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.ManyToOne;
-
-import models.enumeration.RoleType;
-import play.db.ebean.Model;
+import java.util.List;
 
 @Entity
 public class OrganizationUser extends Model {
app/models/PostingComment.java
--- app/models/PostingComment.java
+++ app/models/PostingComment.java
@@ -23,12 +23,13 @@
 import models.enumeration.ResourceType;
 import models.resource.Resource;
 
-import javax.persistence.*;
+import javax.persistence.Entity;
+import javax.persistence.ManyToOne;
 
 @Entity
 public class PostingComment extends Comment {
     private static final long serialVersionUID = 1L;
-    public static Finder<Long, PostingComment> find = new Finder<>(Long.class, PostingComment.class);
+    public static final Finder<Long, PostingComment> find = new Finder<>(Long.class, PostingComment.class);
 
     @ManyToOne
     public Posting posting;
app/models/Project.java
--- app/models/Project.java
+++ app/models/Project.java
@@ -46,7 +46,10 @@
 import javax.persistence.*;
 import javax.servlet.ServletException;
 import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
 
 @Entity
 public class Project extends Model implements LabelOwner {
app/models/ProjectMenuSetting.java
--- app/models/ProjectMenuSetting.java
+++ app/models/ProjectMenuSetting.java
@@ -22,7 +22,9 @@
 
 import play.db.ebean.Model;
 
-import javax.persistence.*;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
 
 @Entity
 public class ProjectMenuSetting extends Model {
app/models/ProjectTransfer.java
--- app/models/ProjectTransfer.java
+++ app/models/ProjectTransfer.java
@@ -38,7 +38,7 @@
 
     private static final long serialVersionUID = 1L;
 
-    public static Finder<Long, ProjectTransfer> find = new Finder<>(Long.class, ProjectTransfer.class);
+    public static final Finder<Long, ProjectTransfer> find = new Finder<>(Long.class, ProjectTransfer.class);
 
     @Id
     public Long id;
app/models/ProjectUser.java
--- app/models/ProjectUser.java
+++ app/models/ProjectUser.java
@@ -20,14 +20,15 @@
  */
 package models;
 
-import java.util.*;
+import models.enumeration.RoleType;
+import play.db.ebean.Model;
 
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.ManyToOne;
-
-import models.enumeration.RoleType;
-import play.db.ebean.Model;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 
 @Entity
 public class ProjectUser extends Model {
app/models/Property.java
--- app/models/Property.java
+++ app/models/Property.java
@@ -24,6 +24,7 @@
 import play.db.ebean.Model;
 import utils.Diagnostic;
 
+import javax.annotation.Nonnull;
 import javax.persistence.Entity;
 import javax.persistence.EnumType;
 import javax.persistence.Enumerated;
@@ -91,7 +92,7 @@
     public static void onStart() {
         Diagnostic.register(new Diagnostic() {
             @Override
-            public List<String> check() {
+            public @Nonnull List<String> check() {
                 List<String> errors = new ArrayList<>();
 
                 for (Property.Name name : Property.Name.values()) {
app/models/PullRequest.java
--- app/models/PullRequest.java
+++ app/models/PullRequest.java
@@ -571,9 +571,9 @@
         return destination;
     }
 
-    public void updateMergedCommitId(Merger.MergeResult merger) {
-        mergedCommitIdFrom = merger.getLeftParentId().getName();
-        mergedCommitIdTo = merger.getMergeCommitId().getName();
+    public void updateMergedCommitId(Merger.MergeResult mergeResult) {
+        mergedCommitIdFrom = mergeResult.getLeftParentId().getName();
+        mergedCommitIdTo = mergeResult.getMergeCommitId().getName();
         update();
     }
 
app/models/PullRequestCommit.java
--- app/models/PullRequestCommit.java
+++ app/models/PullRequestCommit.java
@@ -20,28 +20,22 @@
  */
 package models;
 
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.Nonnull;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-import javax.persistence.Transient;
-
 import org.apache.commons.lang3.StringUtils;
 import play.db.ebean.Model;
 import playRepository.GitCommit;
 import utils.JodaDateUtil;
+
+import javax.annotation.Nonnull;
+import javax.persistence.*;
+import java.util.Date;
+import java.util.List;
 
 @Entity
 public class PullRequestCommit extends Model implements TimelineItem {
 
     private static final long serialVersionUID = -4343181252386722689L;
 
-    public static Finder<Long, PullRequestCommit> find = new Finder<>(Long.class, PullRequestCommit.class);
+    public static final Finder<Long, PullRequestCommit> find = new Finder<>(Long.class, PullRequestCommit.class);
 
     @Id
     public String id;
app/models/PullRequestEvent.java
--- app/models/PullRequestEvent.java
+++ app/models/PullRequestEvent.java
@@ -20,26 +20,25 @@
  */
 package models;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-import javax.persistence.*;
-
-import org.apache.commons.lang3.StringUtils;
 import models.enumeration.EventType;
 import models.enumeration.State;
+import org.apache.commons.lang3.StringUtils;
 import org.joda.time.DateTime;
 import play.db.ebean.Model;
 import utils.EventConstants;
 import utils.JodaDateUtil;
 
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
 @Entity
 public class PullRequestEvent extends Model implements TimelineItem {
 
     private static final long serialVersionUID = 1981361242582594128L;
-    public static Finder<Long, PullRequestEvent> finder = new Finder<>(Long.class, PullRequestEvent.class);
+    public static final Finder<Long, PullRequestEvent> finder = new Finder<>(Long.class, PullRequestEvent.class);
 
     @Id
     public Long id;
app/models/PushedBranch.java
--- app/models/PushedBranch.java
+++ app/models/PushedBranch.java
@@ -20,19 +20,17 @@
  */
 package models;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import org.apache.commons.lang.StringUtils;
+import org.eclipse.jgit.lib.Constants;
+import play.db.ebean.Model;
 
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
-
-import org.apache.commons.lang.StringUtils;
-import org.eclipse.jgit.lib.Constants;
-
-import play.db.ebean.Model;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
 
 /**
  * @author Wansoon Park
app/models/Role.java
--- app/models/Role.java
+++ app/models/Role.java
@@ -20,21 +20,20 @@
  */
 package models;
 
-import java.util.ArrayList;
-import java.util.List;
+import models.enumeration.RoleType;
+import play.db.ebean.Model;
 
 import javax.persistence.CascadeType;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.OneToMany;
-
-import models.enumeration.RoleType;
-import play.db.ebean.Model;
+import java.util.ArrayList;
+import java.util.List;
 
 @Entity
 public class Role extends Model {
     private static final long serialVersionUID = 1L;
-    public static Finder<Long, Role> find = new Finder<>(Long.class,
+    public static final Finder<Long, Role> find = new Finder<>(Long.class,
             Role.class);
 
     @Id
app/models/Search.java
--- app/models/Search.java
+++ app/models/Search.java
@@ -20,7 +20,10 @@
  */
 package models;
 
-import com.avaje.ebean.*;
+import com.avaje.ebean.Expr;
+import com.avaje.ebean.ExpressionList;
+import com.avaje.ebean.Junction;
+import com.avaje.ebean.Page;
 import models.enumeration.Operation;
 import models.enumeration.ProjectScope;
 import models.enumeration.UserState;
app/models/SimpleCommentThread.java
--- app/models/SimpleCommentThread.java
+++ app/models/SimpleCommentThread.java
@@ -23,8 +23,6 @@
 import javax.persistence.DiscriminatorValue;
 import javax.persistence.Entity;
 
-import play.db.ebean.Model.Finder;
-
 /**
  * @author Keesun Baik
  */
app/models/SiteAdmin.java
--- app/models/SiteAdmin.java
+++ app/models/SiteAdmin.java
@@ -20,15 +20,14 @@
  */
 package models;
 
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.OneToOne;
-
 import controllers.UserApp;
 import org.apache.shiro.crypto.RandomNumberGenerator;
 import org.apache.shiro.crypto.SecureRandomNumberGenerator;
 import play.db.ebean.Model;
 
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
 import java.util.Arrays;
 
 @Entity
app/models/Unwatch.java
--- app/models/Unwatch.java
+++ app/models/Unwatch.java
@@ -22,14 +22,14 @@
 
 import models.enumeration.ResourceType;
 
-import javax.persistence.*;
+import javax.persistence.Entity;
 import java.util.List;
 
 @Entity
 public class Unwatch extends UserAction {
     private static final long serialVersionUID = 1L;
 
-    public static Finder<Long, Unwatch> find = new Finder<>(Long.class, Unwatch.class);
+    public static final Finder<Long, Unwatch> find = new Finder<>(Long.class, Unwatch.class);
 
     public static List<Unwatch> findBy(ResourceType resourceType, String resourceId) {
         return findBy(find, resourceType, resourceId);
app/models/User.java
--- app/models/User.java
+++ app/models/User.java
@@ -20,35 +20,33 @@
  */
 package models;
 
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-import javax.persistence.*;
-import javax.persistence.OrderBy;
-import javax.persistence.criteria.Expression;
-
 import com.avaje.ebean.*;
 import controllers.UserApp;
-import models.enumeration.*;
+import models.enumeration.ResourceType;
+import models.enumeration.RoleType;
+import models.enumeration.UserState;
 import models.resource.GlobalResource;
 import models.resource.Resource;
 import models.resource.ResourceConvertible;
-
 import models.support.UserComparator;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.crypto.hash.Sha256Hash;
 import org.apache.shiro.util.ByteSource;
 import play.data.format.Formats;
 import play.data.validation.Constraints;
-import play.data.validation.Constraints.*;
+import play.data.validation.Constraints.Pattern;
+import play.data.validation.Constraints.Required;
+import play.data.validation.Constraints.ValidateWith;
 import play.db.ebean.Model;
 import play.db.ebean.Transactional;
-import scala.reflect.internal.Trees;
 import play.i18n.Messages;
 import utils.JodaDateUtil;
 import utils.ReservedWordsValidator;
 
-import static com.avaje.ebean.Expr.eq;
+import javax.persistence.*;
+import javax.persistence.OrderBy;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 @Table(name = "n4user")
 @Entity
app/models/UserProjectNotification.java
--- app/models/UserProjectNotification.java
+++ app/models/UserProjectNotification.java
@@ -39,7 +39,7 @@
 
     private static final long serialVersionUID = 1L;
 
-    public static Finder<Long, UserProjectNotification> find = new Finder<>(Long.class, UserProjectNotification.class);
+    public static final Finder<Long, UserProjectNotification> find = new Finder<>(Long.class, UserProjectNotification.class);
 
     @Id
     public Long id;
app/models/Watch.java
--- app/models/Watch.java
+++ app/models/Watch.java
@@ -30,7 +30,7 @@
 import org.apache.commons.collections.Predicate;
 import utils.AccessControl;
 
-import javax.persistence.*;
+import javax.persistence.Entity;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -40,7 +40,7 @@
 public class Watch extends UserAction {
     private static final long serialVersionUID = 1L;
 
-    public static Finder<Long, Watch> find = new Finder<>(Long.class, Watch.class);
+    public static final Finder<Long, Watch> find = new Finder<>(Long.class, Watch.class);
 
     public static List<Watch> findBy(ResourceType resourceType, String resourceId) {
         return findBy(find, resourceType, resourceId);
app/models/YobiUpdate.java
--- app/models/YobiUpdate.java
+++ app/models/YobiUpdate.java
@@ -23,18 +23,15 @@
 
 import com.github.zafarkhaja.semver.Version;
 import com.github.zafarkhaja.semver.util.UnexpectedElementTypeException;
-import com.typesafe.config.*;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.InvalidRemoteException;
 import org.eclipse.jgit.lib.Ref;
 import play.Configuration;
-import play.Logger;
 import play.libs.Akka;
 import scala.concurrent.duration.Duration;
 import utils.Config;
 
-import java.util.*;
+import java.util.Collection;
 import java.util.concurrent.TimeUnit;
 
 public class YobiUpdate {
app/models/enumeration/EventType.java
--- app/models/enumeration/EventType.java
+++ app/models/enumeration/EventType.java
@@ -22,7 +22,10 @@
 
 import play.i18n.Messages;
 
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 
 public enum EventType {
 
app/models/resource/GlobalResource.java
--- app/models/resource/GlobalResource.java
+++ app/models/resource/GlobalResource.java
@@ -21,7 +21,6 @@
 package models.resource;
 
 import models.Project;
-import models.resource.Resource;
 
 abstract public class GlobalResource extends Resource {
     @Override
app/models/resource/Resource.java
--- app/models/resource/Resource.java
+++ app/models/resource/Resource.java
@@ -258,7 +258,7 @@
             return null;
         }
 
-        ResourceType resourceType = null;
+        ResourceType resourceType;
 
         try {
             resourceType = ResourceType.getValue(segments[0]);
app/models/resource/ResourcePersistAdapter.java
--- app/models/resource/ResourcePersistAdapter.java
+++ app/models/resource/ResourcePersistAdapter.java
@@ -20,14 +20,13 @@
  */
 package models.resource;
 
-import models.Unwatch;
-import models.Watch;
-
 import com.avaje.ebean.EbeanServer;
 import com.avaje.ebean.Query;
 import com.avaje.ebean.Transaction;
 import com.avaje.ebean.event.BeanPersistAdapter;
 import com.avaje.ebean.event.BeanPersistRequest;
+import models.Unwatch;
+import models.Watch;
 
 /**
  * @see com.avaje.ebean.event.BeanPersistController
app/models/support/FinderTemplate.java
--- app/models/support/FinderTemplate.java
+++ app/models/support/FinderTemplate.java
@@ -20,11 +20,12 @@
  */
 package models.support;
 
-import com.avaje.ebean.*;
+import com.avaje.ebean.ExpressionList;
+import com.avaje.ebean.Page;
+import play.db.ebean.Model;
 
-import play.db.ebean.*;
-
-import java.util.*;
+import java.util.Collection;
+import java.util.List;
 
 public class FinderTemplate {
 
app/models/support/ModelLock.java
--- app/models/support/ModelLock.java
+++ app/models/support/ModelLock.java
@@ -20,12 +20,11 @@
  */
 package models.support;
 
-import java.util.Map;
-
 import com.google.common.collect.MapMaker;
-
 import play.db.ebean.Model;
 
+import java.util.Map;
+
 public class ModelLock<T extends Model> {
     private final Map<T, Object> locks = new MapMaker().weakValues().makeMap();
 
app/models/support/Options.java
--- app/models/support/Options.java
+++ app/models/support/Options.java
@@ -20,7 +20,7 @@
  */
 package models.support;
 
-import java.util.*;
+import java.util.LinkedHashMap;
 
 public class Options extends LinkedHashMap<String, String> {
     private static final long serialVersionUID = 1L;
app/models/support/OrderParam.java
--- app/models/support/OrderParam.java
+++ app/models/support/OrderParam.java
@@ -20,7 +20,7 @@
  */
 package models.support;
 
-import models.enumeration.*;
+import models.enumeration.Direction;
 
 public class OrderParam {
 
app/models/support/OrderParams.java
--- app/models/support/OrderParams.java
+++ app/models/support/OrderParams.java
@@ -20,9 +20,10 @@
  */
 package models.support;
 
-import models.enumeration.*;
+import models.enumeration.Direction;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
 
 
 public class OrderParams {
app/models/support/ReviewSearchCondition.java
--- app/models/support/ReviewSearchCondition.java
+++ app/models/support/ReviewSearchCondition.java
@@ -20,19 +20,22 @@
  */
 package models.support;
 
-import models.*;
-import java.util.List;
-import com.avaje.ebean.Junction;
-import models.enumeration.Direction;
 import com.avaje.ebean.ExpressionList;
+import com.avaje.ebean.Junction;
 import controllers.AbstractPostingApp;
+import models.CommentThread;
+import models.Project;
+import models.ReviewComment;
+import models.enumeration.Direction;
 import org.apache.commons.lang.StringUtils;
+
+import java.util.List;
 
 
 /**
  * The class for searching, sorting and filtering in review menu of a project.
  */
-public class ReviewSearchCondition extends AbstractPostingApp.SearchCondition {
+public class ReviewSearchCondition extends AbstractPostingApp.SearchCondition implements Cloneable {
     public String state;
     public Long authorId;
     public Long participantId;
app/models/support/SearchCondition.java
--- app/models/support/SearchCondition.java
+++ app/models/support/SearchCondition.java
@@ -36,7 +36,7 @@
 import static models.enumeration.ResourceType.ISSUE_COMMENT;
 import static models.enumeration.ResourceType.ISSUE_POST;
 
-public class SearchCondition extends AbstractPostingApp.SearchCondition {
+public class SearchCondition extends AbstractPostingApp.SearchCondition implements Cloneable {
     public String state;
     public Boolean commentedCheck;
     public Long milestoneId;
@@ -256,7 +256,7 @@
             Junction<Issue> junction = el.disjunction();
             junction.icontains("title", filter)
             .icontains("body", filter);
-            List<Object> ids = null;
+            List<Object> ids;
             if( project == null){
                 ids = Issue.finder.where()
                         .icontains("comments.contents", filter).findIds();
app/models/support/SearchParam.java
--- app/models/support/SearchParam.java
+++ app/models/support/SearchParam.java
@@ -20,7 +20,7 @@
  */
 package models.support;
 
-import models.enumeration.*;
+import models.enumeration.Matching;
 
 public class SearchParam {
 
app/models/support/SearchParams.java
--- app/models/support/SearchParams.java
+++ app/models/support/SearchParams.java
@@ -20,9 +20,10 @@
  */
 package models.support;
 
-import models.enumeration.*;
+import models.enumeration.Matching;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
 
 public class SearchParams {
 
app/playRepository/BareCommit.java
--- app/playRepository/BareCommit.java
+++ app/playRepository/BareCommit.java
@@ -26,6 +26,7 @@
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.revwalk.RevWalk;
 import org.eclipse.jgit.treewalk.CanonicalTreeParser;
+import utils.Config;
 
 import java.io.File;
 import java.io.IOException;
@@ -36,8 +37,9 @@
 
 import static org.eclipse.jgit.lib.Constants.HEAD;
 import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
-import static utils.LineEnding.*;
-import static playRepository.BareRepository.*;
+import static playRepository.BareRepository.findFileLineEnding;
+import static utils.LineEnding.addEOL;
+import static utils.LineEnding.changeLineEnding;
 
 public class BareCommit {
     private PersonIdent personIdent;
@@ -138,7 +140,7 @@
 
         boolean isInsertedInTree = false;
         while(!treeParser.eof()){
-            String entryName = new String(treeParser.getEntryPathBuffer(), 0, treeParser.getEntryPathLength());
+            String entryName = new String(treeParser.getEntryPathBuffer(), 0, treeParser.getEntryPathLength(), Config.getCharset());
             String nameForComparison = entryName;
 
             if (treeParser.getEntryFileMode() == FileMode.TREE){
@@ -149,12 +151,12 @@
                 isInsertedInTree = true;
             } else if (nameForComparison.compareTo(fileName) > 0 && isInsertedInTree == false) {
                 formatter.append(fileName, FileMode.REGULAR_FILE, fileObjectId);
-                formatter.append(entryName.getBytes()
+                formatter.append(entryName.getBytes(Config.getCharset())
                         , treeParser.getEntryFileMode()
                         , treeParser.getEntryObjectId());
                 isInsertedInTree = true;
             } else {
-                formatter.append(entryName.getBytes()
+                formatter.append(entryName.getBytes(Config.getCharset())
                         , treeParser.getEntryFileMode()
                         , treeParser.getEntryObjectId());
             }
@@ -174,7 +176,8 @@
     }
 
     private ObjectId createGitObjectWithText(String contents) throws IOException {
-        return objectInserter.insert(OBJ_BLOB, contents.getBytes(), 0, contents.getBytes().length);
+        byte[] bytes = contents.getBytes(Config.getCharset());
+        return objectInserter.insert(OBJ_BLOB, bytes, 0, bytes.length);
     }
 
     private void refUpdate(ObjectId commitId, String refName) throws IOException {
app/playRepository/BareRepository.java
--- app/playRepository/BareRepository.java
+++ app/playRepository/BareRepository.java
@@ -36,7 +36,7 @@
 import java.io.IOException;
 
 import static org.eclipse.jgit.lib.Constants.HEAD;
-import static utils.LineEnding.*;
+import static utils.LineEnding.findLineEnding;
 
 public class BareRepository {
     /**
@@ -58,7 +58,7 @@
         if (loader == null) {
             return null;
         }
-        return new String(loader.getCachedBytes());
+        return new String(loader.getCachedBytes(), utils.Config.getCharset());
     }
 
     public static Repository getRepository(Project project){
@@ -125,7 +125,7 @@
         if(oldObjectId.equals(ObjectId.zeroId())){
             return EndingType.UNDEFINED;
         } else {
-            String fileContents = new String(repository.open(oldObjectId).getBytes());
+            String fileContents = new String(repository.open(oldObjectId).getBytes(), utils.Config.getCharset());
             return findLineEnding(fileContents);
         }
     }
app/playRepository/GitRepository.java
--- app/playRepository/GitRepository.java
+++ app/playRepository/GitRepository.java
@@ -162,7 +162,7 @@
     }
 
     public static void cloneLocalRepository(Project originalProject, Project forkProject)
-            throws IOException, GitAPIException {
+            throws Exception {
         try {
             cloneHardLinkedRepository(originalProject, forkProject);
         } catch (Exception e) {
@@ -638,7 +638,7 @@
      * initializing {@code Cache} used in the repository.
      */
     @Override
-    public void delete() {
+    public void delete() throws Exception {
         repository.close();
         WindowCacheConfig config = new WindowCacheConfig();
         config.install();
@@ -1065,8 +1065,8 @@
             if (diffs.size() > BLAME_FILE_LIMIT) {
                 String msg = String.format("Reject to get related authors " +
                         "from changes because of performance issue: The " +
-                        "changes include %n files and it exceeds our limit " +
-                        "of '%n' files.", diffs.size(), BLAME_FILE_LIMIT);
+                        "changes include %d files and it exceeds our limit " +
+                        "of '%d' files.", diffs.size(), BLAME_FILE_LIMIT);
                 throw new LimitExceededException(msg);
             }
 
app/playRepository/PlayRepository.java
--- app/playRepository/PlayRepository.java
+++ app/playRepository/PlayRepository.java
@@ -42,7 +42,7 @@
 
     public abstract byte[] getRawFile(String revision, String path) throws IOException, SVNException;
 
-    public abstract void delete();
+    public abstract void delete() throws Exception;
 
     public abstract String getPatch(String commitId) throws IOException, SVNException;
 
app/playRepository/RepositoryService.java
--- app/playRepository/RepositoryService.java
+++ app/playRepository/RepositoryService.java
@@ -59,7 +59,7 @@
      * @see {@link playRepository.PlayRepository#delete()}
      */
     public static void deleteRepository(Project project)
-            throws IOException, ServletException {
+            throws Exception {
         RepositoryService.getRepository(project).delete();
     }
 
@@ -67,8 +67,7 @@
      * @see {@link #deleteRepository(Project)}
      * @see {@link PlayRepository#create()}
      */
-    public static void createRepository(Project project) throws IOException, ServletException,
-            UnsupportedOperationException, SVNException {
+    public static void createRepository(Project project) throws Exception {
         RepositoryService.deleteRepository(project);
         RepositoryService.getRepository(project).create();
     }
app/playRepository/SVNRepository.java
--- app/playRepository/SVNRepository.java
+++ app/playRepository/SVNRepository.java
@@ -40,13 +40,11 @@
 import org.tmatesoft.svn.core.wc.SVNDiffClient;
 import org.tmatesoft.svn.core.wc.SVNRevision;
 import play.libs.Json;
+import utils.Config;
 import utils.FileUtil;
 import utils.GravatarUtil;
 
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -210,22 +208,22 @@
     }
 
     @Override
-    public void delete() {
+    public void delete() throws Exception {
         FileUtil.rm_rf(new File(getRepoPrefix() + ownerName + "/" + projectName));
     }
 
     @Override
-    public String getPatch(String commitId) throws SVNException {
+    public String getPatch(String commitId) throws SVNException, UnsupportedEncodingException {
         long rev = Integer.parseInt(commitId);
         return getPatch(rev - 1, rev);
     }
 
     @Override
-    public String getPatch(String revA, String revB) throws SVNException {
+    public String getPatch(String revA, String revB) throws SVNException, UnsupportedEncodingException {
         return getPatch(Long.parseLong(revA), Long.parseLong(revB));
     }
 
-    private String getPatch(long revA, long revB) throws SVNException {
+    private String getPatch(long revA, long revB) throws SVNException, UnsupportedEncodingException {
         // Prepare required arguments.
         SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName));
 
@@ -239,7 +237,7 @@
         diffClient.doDiff(svnURL, null, SVNRevision.create(revA), SVNRevision.create(revB),
                 SVNDepth.INFINITY, true, byteArrayOutputStream);
 
-        return byteArrayOutputStream.toString();
+        return byteArrayOutputStream.toString(Config.getCharset().name());
     }
 
     @Override
@@ -346,7 +344,7 @@
 
     @Override
     public boolean isFile(String path, String revStr) throws SVNException {
-        return isFile(path, Long.valueOf(revStr));
+        return isFile(path, Long.parseLong(revStr));
     }
 
 
app/utils/BasicAuthAction.java
--- app/utils/BasicAuthAction.java
+++ app/utils/BasicAuthAction.java
@@ -23,14 +23,13 @@
 import controllers.UserApp;
 import models.User;
 import org.apache.commons.codec.binary.Base64;
+import play.libs.F.Promise;
 import play.mvc.Action;
 import play.mvc.Http;
 import play.mvc.Http.Context;
 import play.mvc.Http.Request;
 import play.mvc.Http.Response;
 import play.mvc.Result;
-import play.mvc.Result;
-import play.libs.F.Promise;
 
 import java.io.UnsupportedEncodingException;
 
@@ -59,10 +58,7 @@
             return null;
         }
 
-        String userpassBase64 = credentials.substring(6);
-        byte[] userpassBytes;
-
-        userpassBytes = Base64.decodeBase64(userpassBase64.getBytes());
+        byte[] userpassBytes = Base64.decodeBase64(credentials.substring(6));
 
         // Use ISO-8859-1 only and not others, even if in RFC 2616, Section 2.2 "Basic Rules" allows
         // TEXT to be encoded according to the rules of RFC 2047.
app/utils/Config.java
--- app/utils/Config.java
+++ app/utils/Config.java
@@ -26,6 +26,7 @@
 import play.mvc.Http;
 
 import java.net.*;
+import java.nio.charset.Charset;
 import java.util.Enumeration;
 
 public class Config {
@@ -55,10 +56,6 @@
 
     public static String getHostport(String defaultValue) {
         play.Configuration config = play.Configuration.root();
-
-        if (config == null) {
-            return defaultValue;
-        }
 
         String hostname = play.Configuration.root().getString("application.hostname");
 
@@ -106,11 +103,9 @@
     public static String getHostname() {
         play.Configuration config = play.Configuration.root();
 
-        if (config != null) {
-            String hostname = play.Configuration.root().getString("application.hostname");
-            if (hostname != null && !hostname.isEmpty()) {
-                return hostname;
-            }
+        String hostname = play.Configuration.root().getString("application.hostname");
+        if (hostname != null && !hostname.isEmpty()) {
+            return hostname;
         }
 
         try {
@@ -138,10 +133,6 @@
 
     public static String getScheme(String defaultValue) {
         play.Configuration config = play.Configuration.root();
-
-        if (config == null) {
-            return defaultValue;
-        }
 
         String scheme = config.getString("application.scheme");
 
@@ -281,4 +272,8 @@
             return user + "@" + config.getString(prefix + ".domain", getHostname());
         }
     }
+
+    public static Charset getCharset() {
+        return Charset.forName("UTF-8");
+    }
 }
app/utils/FastHttpDateFormat.java
--- app/utils/FastHttpDateFormat.java
+++ app/utils/FastHttpDateFormat.java
@@ -14,14 +14,15 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package utils;
 
-import play.*;
-
-import java.text.*;
-import java.util.*;
-import java.util.concurrent.*;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Utility class to generate HTTP dates.
@@ -34,28 +35,31 @@
     // -------------------------------------------------------------- Variables
 
 
-    protected static final int CACHE_SIZE =
+    private static final int CACHE_SIZE =
         Integer.parseInt(System.getProperty("org.apache.tomcat.util.http.FastHttpDateFormat.CACHE_SIZE", "1000"));
 
 
     /**
-     * HTTP date format.
+     * The only date format permitted when generating HTTP headers.
      */
-    protected static final SimpleDateFormat format =
-        new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
+    public static final String RFC1123_DATE =
+            "EEE, dd MMM yyyy HH:mm:ss zzz";
+
+    private static final SimpleDateFormat format =
+            new SimpleDateFormat(RFC1123_DATE, Locale.US);
 
 
     /**
      * The set of SimpleDateFormat formats to use in getDateHeader().
      */
-    protected static final SimpleDateFormat formats[] = {
-        new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
+    private static final SimpleDateFormat formats[] = {
+        new SimpleDateFormat(RFC1123_DATE, Locale.US),
         new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
         new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
     };
 
 
-    protected final static TimeZone gmtZone = TimeZone.getTimeZone("GMT");
+    private static final TimeZone gmtZone = TimeZone.getTimeZone("GMT");
 
 
     /**
@@ -75,27 +79,27 @@
     /**
      * Instant on which the currentDate object was generated.
      */
-    protected static long currentDateGenerated = 0L;
+    private static volatile long currentDateGenerated = 0L;
 
 
     /**
      * Current formatted date.
      */
-    protected static String currentDate = null;
+    private static String currentDate = null;
 
 
     /**
      * Formatter cache.
      */
-    protected static final ConcurrentHashMap<Long, String> formatCache =
-        new ConcurrentHashMap<>(CACHE_SIZE);
+    private static final ConcurrentHashMap<Long, String> formatCache =
+            new ConcurrentHashMap<>(CACHE_SIZE);
 
 
     /**
      * Parser cache.
      */
-    protected static final ConcurrentHashMap<String, Long> parseCache =
-        new ConcurrentHashMap<>(CACHE_SIZE);
+    private static final ConcurrentHashMap<String, Long> parseCache =
+            new ConcurrentHashMap<>(CACHE_SIZE);
 
 
     // --------------------------------------------------------- Public Methods
@@ -110,8 +114,8 @@
         if ((now - currentDateGenerated) > 1000) {
             synchronized (format) {
                 if ((now - currentDateGenerated) > 1000) {
-                    currentDateGenerated = now;
                     currentDate = format.format(new Date(now));
+                    currentDateGenerated = now;
                 }
             }
         }
@@ -126,26 +130,24 @@
     public static final String formatDate
         (long value, DateFormat threadLocalformat) {
 
-        Long longValue = value;
+        Long longValue = new Long(value);
         String cachedDate = formatCache.get(longValue);
-        if (cachedDate != null)
+        if (cachedDate != null) {
             return cachedDate;
+        }
 
-        String newDate;
+        String newDate = null;
         Date dateValue = new Date(value);
         if (threadLocalformat != null) {
             newDate = threadLocalformat.format(dateValue);
             updateFormatCache(longValue, newDate);
         } else {
-            synchronized (formatCache) {
-                synchronized (format) {
-                    newDate = format.format(dateValue);
-                }
-                updateFormatCache(longValue, newDate);
+            synchronized (format) {
+                newDate = format.format(dateValue);
             }
+            updateFormatCache(longValue, newDate);
         }
         return newDate;
-
     }
 
 
@@ -155,27 +157,24 @@
     public static final long parseDate(String value,
                                        DateFormat[] threadLocalformats) {
 
-        Logger.debug("parseDate " + value);
         Long cachedDate = parseCache.get(value);
-        if (cachedDate != null)
-            return cachedDate;
+        if (cachedDate != null) {
+            return cachedDate.longValue();
+        }
 
-        Long date;
+        Long date = null;
         if (threadLocalformats != null) {
             date = internalParseDate(value, threadLocalformats);
             updateParseCache(value, date);
         } else {
-            synchronized (parseCache) {
-                date = internalParseDate(value, formats);
-                updateParseCache(value, date);
-            }
+            date = internalParseDate(value, formats);
+            updateParseCache(value, date);
         }
         if (date == null) {
             return (-1L);
-        } else {
-            return date;
         }
 
+        return date.longValue();
     }
 
 
@@ -188,13 +187,14 @@
         for (int i = 0; (date == null) && (i < formats.length); i++) {
             try {
                 date = formats[i].parse(value);
-            } catch (ParseException ignored) {
+            } catch (ParseException e) {
+                // Ignore
             }
         }
         if (date == null) {
             return null;
         }
-        return date.getTime();
+        return new Long(date.getTime());
     }
 
 
app/utils/FileUtil.java
--- app/utils/FileUtil.java
+++ app/utils/FileUtil.java
@@ -32,11 +32,12 @@
 
 public class FileUtil {
 
-    public static final int MAX_SIZE_FOR_BINARY_DETECTION = 512;
-
-    public static void rm_rf(File file){
+    public static void rm_rf(File file) throws Exception {
         if(file.isDirectory()){
             File[] list = file.listFiles();
+            if (list == null) {
+                throw new Exception("Unexpected error while deleting: " + file);
+            }
             for (File f : list) {
                 rm_rf(f);
             }
app/utils/Markdown.java
--- app/utils/Markdown.java
+++ app/utils/Markdown.java
@@ -34,6 +34,7 @@
 import java.io.Reader;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.nio.charset.Charset;
 
 public class Markdown {
 
@@ -50,15 +51,15 @@
 
         try {
             is = Thread.currentThread().getContextClassLoader().getResourceAsStream(XSS_JS_FILE);
-            reader = new InputStreamReader(is);
+            reader = new InputStreamReader(is, Config.getCharset());
             _engine.eval(reader);
 
             is = Thread.currentThread().getContextClassLoader().getResourceAsStream(MARKED_JS_FILE);
-            reader = new InputStreamReader(is);
+            reader = new InputStreamReader(is, Config.getCharset());
             _engine.eval(reader);
 
             is = Thread.currentThread().getContextClassLoader().getResourceAsStream(HIGHLIGHT_JS_FILE);
-            reader = new InputStreamReader(is);
+            reader = new InputStreamReader(is, Config.getCharset());
             _engine.eval(reader);
         } catch (Exception ex) {
             throw new RuntimeException(ex);
app/utils/MomentUtil.java
--- app/utils/MomentUtil.java
+++ app/utils/MomentUtil.java
@@ -46,7 +46,7 @@
 
         try {
             is = Thread.currentThread().getContextClassLoader().getResourceAsStream(MOMENT_JS_FILE);
-            reader = new InputStreamReader(is);
+            reader = new InputStreamReader(is, Config.getCharset());
             _engine.eval(reader);
         } catch (Exception ex) {
             throw new RuntimeException(ex);
app/utils/PlayServletRequest.java
--- app/utils/PlayServletRequest.java
+++ app/utils/PlayServletRequest.java
@@ -20,41 +20,21 @@
  */
 package utils;
 
-import java.io.*;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.security.Principal;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.servlet.AsyncContext;
-import javax.servlet.DispatcherType;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.ServletInputStream;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.Part;
-
 import org.tmatesoft.svn.core.internal.util.SVNEncodingUtil;
 import play.Play;
 import play.i18n.Lang;
 import play.mvc.Http;
 import play.mvc.Http.RawBuffer;
 import play.mvc.Http.Request;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+import java.io.*;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.Principal;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 public class PlayServletRequest implements HttpServletRequest {
 
@@ -516,15 +496,7 @@
 
     @Override
     public HttpSession getSession(boolean create) {
-        if (httpSession != null) {
-            return httpSession;
-        }
-
-        if (create) {
-            return new PlayServletSession(new PlayServletContext());
-        } else {
-            return null;
-        }
+        return httpSession;
     }
 
     @Override
app/utils/PlayServletResponse.java
--- app/utils/PlayServletResponse.java
+++ app/utils/PlayServletResponse.java
@@ -25,6 +25,7 @@
 import javax.servlet.*;
 import javax.servlet.http.*;
 import java.io.*;
+import java.nio.charset.Charset;
 import java.util.*;
 
 public class PlayServletResponse implements HttpServletResponse {
@@ -116,7 +117,9 @@
         this.statusLock = new Object();
         this.inputStream = new PipedInputStream();
         this.outputStream = new ChunkedOutputStream(new PipedOutputStream(this.inputStream));
-        this.pw = new PrintWriter(this.outputStream);
+        this.pw = new PrintWriter(
+                new BufferedWriter(new OutputStreamWriter(this.outputStream, Config.getCharset())),
+                false);
     }
 
     @Override
@@ -221,7 +224,7 @@
 
     @Override
     public void addDateHeader(String name, long date) {
-        addHeader(name, FastHttpDateFormat.formatDate(date, FastHttpDateFormat.format));
+        addHeader(name, FastHttpDateFormat.formatDate(date, null));
     }
 
     @Override
@@ -329,7 +332,7 @@
 
     @Override
     public void setDateHeader(String name, long date) {
-        this.response.setHeader(name, FastHttpDateFormat.formatDate(date, FastHttpDateFormat.format));
+        this.response.setHeader(name, FastHttpDateFormat.formatDate(date, null));
     }
 
     @Override
app/utils/RouteUtil.java
--- app/utils/RouteUtil.java
+++ app/utils/RouteUtil.java
@@ -34,7 +34,7 @@
 import utils.TemplateHelper.DiffRenderer$;
 
 public class RouteUtil {
-    public static DiffRenderer$ diffRenderer = new DiffRenderer$();
+    public static final DiffRenderer$ diffRenderer = new DiffRenderer$();
 
     public static String getUrl(ResourceType resourceType, String resourceId) {
         Long longId = Long.valueOf(resourceId);
app/utils/TemplateHelper.scala
--- app/utils/TemplateHelper.scala
+++ app/utils/TemplateHelper.scala
@@ -1,5 +1,6 @@
 package utils
 
+import org.apache.commons.lang3.StringUtils
 import play.mvc.Call
 import org.joda.time.DateTimeConstants
 import org.apache.commons.io.FilenameUtils
@@ -105,10 +106,8 @@
     }
   }
 
-  def equals(a: String, b: String) = (a == b) || a.equals(b)
-
   def equalsThen(a: String, b: String, thenStr: String): String = {
-    if(a != null && b != null && equals(a, b)){
+    if(a != null && b != null && StringUtils.equals(a, b)){
       thenStr
     } else {
       ""
@@ -125,7 +124,7 @@
 
   // Whether the given uris are pointing the same resource.
   def resourceEquals(a: URI, b: URI) =
-    nullOrEquals(a.getHost, b.getHost) && getPort(a) == getPort(b) && equals(a.getPath, b.getPath)
+    nullOrEquals(a.getHost, b.getHost) && getPort(a) == getPort(b) && StringUtils.equals(a.getPath, b.getPath)
 
   // Get the url to return to the list page from the view page.
   // Return the referrer if the it is the uri for the list page, an/ return the
@@ -520,7 +519,7 @@
     }
 
     def getCorrectedPath(filePath:String, fileName:String):String = {
-      if((filePath != "") && (filePath.substring(filePath.length() - 1) == "/")){
+      if(StringUtils.isNotEmpty(filePath) && (filePath.substring(filePath.length() - 1) == "/")){
         filePath + fileName
       } else {
         filePath + "/" + fileName
app/views/code/svnDiff.scala.html
--- app/views/code/svnDiff.scala.html
+++ app/views/code/svnDiff.scala.html
@@ -27,6 +27,7 @@
 @import utils.AccessControl._
 @import play.libs.Json.toJson
 @import utils.Markdown
+@import org.apache.commons.lang3.StringUtils
 
 @projectLayout(Messages("code.commits") + " @" + commit.getId, project, utils.MenuType.CODE) {
 @projectMenu(project, utils.MenuType.CODE, "main-menu-only")
@@ -42,7 +43,7 @@
                 @defining(RepositoryService.getRepository(project).getBranchNames()) { branches =>
                     @for(branch <- branches){
                         @common.branchItem("history", project, branch, null,
-                            utils.TemplateHelper.equals(branch, selectedBranch))
+                            StringUtils.equals(branch, selectedBranch))
                     }
                 }
                 </ul>
test/controllers/ProjectAppTest.java
--- test/controllers/ProjectAppTest.java
+++ test/controllers/ProjectAppTest.java
@@ -436,7 +436,7 @@
     }
 
     @Test
-    public void testAcceptTransfer() throws IOException, ServletException, SVNException {
+    public void testAcceptTransfer() throws Exception {
         //Given
         GitRepository.setRepoPrefix("resources/test/repo/git/");
 
@@ -462,7 +462,7 @@
     }
 
     @Test
-    public void testAcceptTransferWithWrongKey() throws IOException, ServletException, SVNException {
+    public void testAcceptTransferWithWrongKey() throws Exception {
         //Given
         GitRepository.setRepoPrefix("resources/test/repo/git/");
 
test/models/CodeCommentThreadTest.java
--- test/models/CodeCommentThreadTest.java
+++ test/models/CodeCommentThreadTest.java
@@ -28,7 +28,6 @@
 import org.junit.Test;
 import playRepository.BareCommit;
 import playRepository.GitRepository;
-import support.Git;
 import utils.JodaDateUtil;
 
 import java.io.File;
@@ -55,7 +54,7 @@
     }
 
     @After
-    public void after() {
+    public void after() throws Exception {
         rm_rf(new File(REPO_PREFIX));
     }
 
test/models/PullRequestTest.java
--- test/models/PullRequestTest.java
+++ test/models/PullRequestTest.java
@@ -20,7 +20,6 @@
  */
 package models;
 
-import errors.PullRequestException;
 import org.apache.commons.lang3.time.DateUtils;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.errors.GitAPIException;
@@ -65,8 +64,7 @@
     private Project forkedProject;
 
     @Before
-    public void initRepositories() throws IOException, GitAPIException, ServletException,
-            PullRequestException, SVNException {
+    public void initRepositories() throws Exception {
         GitRepository.setRepoPrefix(REPO_PREFIX);
 
         app = support.Helpers.makeTestApplication();
@@ -124,7 +122,7 @@
     }
 
     @After
-    public void after() {
+    public void after() throws Exception {
         rm_rf(new File(REPO_PREFIX));
         rm_rf(new File(LOCAL_REPO_PREFIX));
         Helpers.stop(app);
Add a comment
List