Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Merge branch 'fix/by-idea-and-findbugs' into 'next'
Browse files Browse the repository at this point in the history
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: 채수원 <sw.chae@navercorp.com>
  • Loading branch information
doortts committed Mar 12, 2015
2 parents 6e17a7c + 9925b83 commit ca48c65
Show file tree
Hide file tree
Showing 72 changed files with 270 additions and 305 deletions.
6 changes: 3 additions & 3 deletions app/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ private String createSeed(String basicSeed) {
}

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) {
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/BoardApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Objects;

import static com.avaje.ebean.Expr.icontains;

Expand Down Expand Up @@ -244,7 +245,7 @@ public void run() {

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();
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/CodeHistoryApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static Result show(String ownerName, String projectName, String commitId)
Project project = Project.findByOwnerAndProjectName(ownerName, projectName);
PlayRepository repository = RepositoryService.getRepository(project);

Commit commit = null;
Commit commit;

try {
commit = repository.getCommit(commitId);
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/ImportApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -57,7 +58,7 @@ public static Result importForm() {
}

@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");
}
Expand Down Expand Up @@ -180,7 +181,7 @@ private static ValidationResult validateForm(Form<Project> newProjectForm, Organ
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));
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/IssueApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ public static Result userIssues(String state, String format, int pageNum) throws
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);

Expand Down Expand Up @@ -312,7 +309,7 @@ public static Result massUpdate(String ownerName, String projectName) {
if(hasAssignee(issue)) {
oldAssignee = issue.assignee.user;
}
Assignee newAssignee = null;
Assignee newAssignee;
if (issueMassUpdate.assignee.isAnonymous()) {
newAssignee = null;
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/PullRequestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ public Result getResult() {

}

public static class SearchCondition {
public static class SearchCondition implements Cloneable {
public Project project;
public String filter;
public Long contributorId;
Expand Down
4 changes: 2 additions & 2 deletions app/models/AbstractPosting.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down
8 changes: 3 additions & 5 deletions app/models/Assignee.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion app/models/Attachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package models;

import utils.AttachmentCache;
import controllers.AttachmentApp;
import models.enumeration.ResourceType;
import models.resource.GlobalResource;
Expand All @@ -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;

Expand Down
1 change: 0 additions & 1 deletion app/models/AuthInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package models;

import play.data.validation.Constraints;
import utils.ReservedWordsValidator;

public class AuthInfo {
@Constraints.Required
Expand Down
10 changes: 4 additions & 6 deletions app/models/Issue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,11 +69,8 @@ public class Issue extends AbstractPosting implements LabelOwner {
@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;
Expand Down Expand Up @@ -371,7 +369,7 @@ public boolean assignedUserEquals(Assignee otherAssignee) {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/IssueComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions app/models/IssueEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,7 +57,7 @@ public class IssueEvent extends Model implements TimelineItem {
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);

/**
Expand Down
2 changes: 1 addition & 1 deletion app/models/IssueLabelCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions app/models/LabelOwner.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
*/
package models;

import java.util.Set;

import models.resource.ResourceConvertible;

import java.util.Set;

/**
* @see models.resource.ResourceConvertible
*/
Expand Down
18 changes: 11 additions & 7 deletions app/models/Milestone.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/NonRangedCodeCommentThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions app/models/NotificationEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package models;

import com.avaje.ebean.RawSql;
import com.avaje.ebean.RawSqlBuilder;
import controllers.UserApp;
import controllers.routes;
Expand All @@ -42,7 +41,6 @@
import playRepository.*;
import scala.concurrent.duration.Duration;
import utils.AccessControl;
import utils.Config;
import utils.EventConstants;
import utils.RouteUtil;

Expand All @@ -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;
Expand All @@ -66,7 +67,7 @@ public class NotificationEvent extends Model {
@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;

Expand Down
6 changes: 3 additions & 3 deletions app/models/NotificationMail.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -69,7 +69,7 @@ public class NotificationMail extends Model {
@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() {
Expand Down
7 changes: 3 additions & 4 deletions app/models/OrganizationUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions app/models/PostingComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion app/models/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit ca48c65

Please sign in to comment.