Skip to content

Commit

Permalink
Merge pull request zanata#212 from zanata/cleanup-warnings
Browse files Browse the repository at this point in the history
WIP: Clean up some findbugs warnings
  • Loading branch information
seanf committed Apr 3, 2014
2 parents e721197 + 6ee37fa commit 1f3f7bf
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://help.github.com/articles/dealing-with-line-endings

# This setting tells git to always normalize the files specified.
# When committed they are stored with LF, on checkout they are
# This setting tells git always to normalize the files specified.
# When committed they are stored with LF, on checkout they are
# converted to the OS's native line endings.
* text

Expand Down
1 change: 0 additions & 1 deletion branch-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ git commit pom.xml */pom.xml -m "prepare for next development iteration"

# push all the changes back to the server
git push origin legacy release integration/master

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public ConfigurableNgramAnalyzer(int ngramMinLength, int ngramMaxLength,
this.foldCase = foldCase;
}

@SuppressWarnings("resource") // caller should close
@Override
public TokenStream tokenStream(String fieldName, Reader reader) {
TokenStream tokenStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
*/
package org.zanata.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import javax.validation.constraints.NotNull;

import lombok.NoArgsConstructor;
Expand All @@ -46,7 +49,8 @@
@Setter
@NoArgsConstructor
@ToString(of = "comment")
public class HTermComment {
public class HTermComment implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;

private String comment;
Expand Down
3 changes: 1 addition & 2 deletions zanata-model/src/main/java/org/zanata/model/HTextFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ private void updateContentHash() {
this.setContentHash(HashUtil.generateHash(contents));
}

private String toBCP47(HLocale hLocale) {
HLocale docLocale = document.getLocale();
private static String toBCP47(HLocale docLocale) {
if (docLocale == null) {
// *should* only happen in tests
log.warn("null locale, assuming 'en'");
Expand Down
22 changes: 11 additions & 11 deletions zanata-model/src/test/java/org/zanata/model/HGlossaryEntryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public class HGlossaryEntryTest {
@BeforeTest
public void setup() {
entry = new HGlossaryEntry();
entry.setId(new Long(1));
entry.setId(1L);
entry.setVersionNum(1);
entry.setCreationDate(new Date());
entry.setLastChanged(new Date());

HLocale srcLang = new HLocale(LocaleId.EN_US);
setupHLocale(srcLang, new Long(1));
setupHLocale(srcLang, 1L);

entry.setSrcLocale(srcLang);
entry.setSourceRef("source ref");
Expand All @@ -59,7 +59,7 @@ public void hashMapDataTerm1Test() {

// Glossary Term 1 - EN_US
HLocale term1Locale =
setupTerm(new Long(1), "TERM 1", LocaleId.EN_US, new Long(1));
setupTerm(1L, "TERM 1", LocaleId.EN_US, 1L);

assertEquals(1, entry.getGlossaryTerms().size());
assertEquals(true, entry.getGlossaryTerms().containsKey(term1Locale));
Expand All @@ -74,11 +74,11 @@ public void hashMapDataTerm2Test() {

// Glossary Term 1 - EN_US
HLocale term1Locale =
setupTerm(new Long(1), "TERM 1", LocaleId.EN_US, new Long(1));
setupTerm(1L, "TERM 1", LocaleId.EN_US, 1L);

// Glossary Term 2 - DE
HLocale term2Locale =
setupTerm(new Long(2), "TERM 2", LocaleId.DE, new Long(2));
setupTerm(2L, "TERM 2", LocaleId.DE, 2L);

assertEquals(2, entry.getGlossaryTerms().size());
assertEquals(true, entry.getGlossaryTerms().containsKey(term2Locale));
Expand All @@ -93,15 +93,15 @@ public void hashMapDataTerm3Test() {

// Glossary Term 1 - EN_US
HLocale term1Locale =
setupTerm(new Long(1), "TERM 1", LocaleId.EN_US, new Long(1));
setupTerm(1L, "TERM 1", LocaleId.EN_US, 1L);

// Glossary Term 2 - DE
HLocale term2Locale =
setupTerm(new Long(2), "TERM 2", LocaleId.DE, new Long(2));
setupTerm(2L, "TERM 2", LocaleId.DE, 2L);

// Glossary Term 3 - ES
HLocale term3Locale =
setupTerm(new Long(3), "TERM 3", LocaleId.ES, new Long(3));
setupTerm(3L, "TERM 3", LocaleId.ES, 3L);

assertEquals(3, entry.getGlossaryTerms().size());
assertEquals(true, entry.getGlossaryTerms().containsKey(term3Locale));
Expand All @@ -115,13 +115,13 @@ public void hashMapDataTest() {
entry.getGlossaryTerms().clear();

// Glossary Term 1 - EN_US
setupTerm(new Long(1), "TERM 1", LocaleId.EN_US, new Long(1));
setupTerm(1L, "TERM 1", LocaleId.EN_US, 1L);

// Glossary Term 2 - DE
setupTerm(new Long(2), "TERM 2", LocaleId.DE, new Long(2));
setupTerm(2L, "TERM 2", LocaleId.DE, 2L);

// Glossary Term 3 - ES
setupTerm(new Long(3), "TERM 3", LocaleId.ES, new Long(3));
setupTerm(3L, "TERM 3", LocaleId.ES, 3L);

for (HLocale key : entry.getGlossaryTerms().keySet()) {
assertTrue(entry.getGlossaryTerms().containsKey(key));
Expand Down
12 changes: 3 additions & 9 deletions zanata-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
<usedDependency>javax.xml.bind:jaxb-api</usedDependency>
<!-- runtime dep for liquibase logging -->
<usedDependency>com.mattbertolini:liquibase-slf4j</usedDependency>
<usedDependency>com.google.code.findbugs:annotations</usedDependency>
<usedDependency>org.opensymphony.quartz:quartz</usedDependency>
<!-- Used indirectly by org.zanata.arquillian.Deployments -->
<usedDependency>org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api</usedDependency>
Expand Down Expand Up @@ -442,22 +441,17 @@

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<argLine>-Dconcordion.output.dir=${concordion.output.dir}</argLine>
<junitArtifactName>none:none</junitArtifactName>
<testNGArtifactName>org.testng:testng</testNGArtifactName>
<forkMode>once</forkMode>
<argLine xml:space="preserve">-Xmx1024m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=${project.build.directory} -Dsun.lang.ClassLoader.allowArraySyntax=true</argLine>
<forkCount>1.5C</forkCount>
<reuseForks>false</reuseForks>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/AllNonContainerTests.tng.xml</suiteXmlFile>
</suiteXmlFiles>
<runOrder>alphabetical</runOrder>
<!-- TODO try parallel execution
<parallel>methods</parallel>
<threadCount>4</threadCount>
-->
</configuration>
<!-- below trick is to let surefire run both junit and testng.
see http://stackoverflow.com/questions/1232853/how-to-execute-junit-and-testng-tests-in-same-project-using-maven-surefire-plugi-->
Expand Down
1 change: 0 additions & 1 deletion zanata-war/src/etc/FillInTranslationGap.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,3 @@ genPropNames.each {
}
log.info("processed {}", skeleton.name)
}

Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ public Status(String locale, String nativeName,

@Override
public int compareTo(Status o) {
int per =
getStats().getTotal() == 0 ? 0 : (int) Math.ceil(100.0
* getStats().getApproved() / getStats().getTotal());
int comparePer =
o.getStats().getTotal() == 0 ? 0 : (int) Math.ceil(100.0
* o.getStats().getApproved()
/ o.getStats().getTotal());

return Double.compare(comparePer, per);
// TODO compare by locale too?
// TODO if totals are the same, we only need to compare approved
return Double.compare(o.getPercentApproved(), getPercentApproved());
}

private double getPercentApproved() {
// TODO move to TranslationStatistics.getPercentApproved() ?
long total = getStats().getTotal();
long approved = getStats().getApproved();
return total == 0 ? 0 : 100d * approved / total;
}
}

Expand Down
2 changes: 1 addition & 1 deletion zanata-war/src/main/java/org/zanata/dao/AccountDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ public List<HAccount> getAllMergedAccounts(HAccount mergedInto) {
"from HAccount as a where a.mergedInto = :mergedInto");
query.setParameter("mergedInto", mergedInto);
query.setComment("AccountDAO.getAllMergedAccounts");
return query.list();
return (List<HAccount>) query.list();
}
}
2 changes: 1 addition & 1 deletion zanata-war/src/main/java/org/zanata/dao/ActivityDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public List<Activity> findLatestActivities(long personId, int offset,
query.setFirstResult(offset);
query.setCacheable(true);
query.setComment("activityDAO.findLatestActivities");
return query.list();
return (List<Activity>) query.list();
}

public int getActivityCountByActor(Long personId) {
Expand Down
8 changes: 4 additions & 4 deletions zanata-war/src/main/java/org/zanata/dao/PersonDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ public boolean isUserInLanguageTeamWithRoles(HPerson person,
.setParameter("language", language);

if (isTranslator != null) {
q.setParameter("isTranslator", isTranslator.booleanValue());
q.setParameter("isTranslator", isTranslator);
}
if (isReviewer != null) {
q.setParameter("isReviewer", isReviewer.booleanValue());
q.setParameter("isReviewer", isReviewer);
}
if (isCoordinator != null) {
q.setParameter("isCoordinator", isCoordinator.booleanValue());
q.setParameter("isCoordinator", isCoordinator);
}

q.setCacheable(false).setComment(
Expand All @@ -207,7 +207,7 @@ public List<HLocaleMember> getAllLanguageTeamMemberships(HPerson person) {
.setParameter("person", person);
q.setCacheable(false).setComment(
"PersonDAO.getAllLanguageTeamMemberships");
return q.list();
return (List<HLocaleMember>) q.list();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
// Implementation copied from
// https://source.jboss.org/browse/Seam/branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/navigation/SafeActions.java?r=14141
// following https://community.jboss.org/message/688860#688860
// TODO see if this can be removed - see also https://issues.jboss.org/browse/JBSEAM-4800
public class FixedSafeActions extends org.jboss.seam.navigation.SafeActions {

private Set<String> safeActions = Collections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.google.gwt.user.client.rpc.IsSerializable;
import com.google.inject.Singleton;

import javax.annotation.Nonnull;

@Singleton
public class UserConfigHolder {
public static final Predicate<ContentState> INCOMPLETE_PREDICATE =
Expand All @@ -46,7 +48,7 @@ public boolean apply(ContentState contentState) {
public static final Predicate<ContentState> DRAFT_PREDICATE =
new Predicate<ContentState>() {
@Override
public boolean apply(ContentState contentState) {
public boolean apply(@Nonnull ContentState contentState) {
return contentState.isRejectedOrFuzzy();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void renderTable(List<TransMemoryResultItem> memories,
resultTable.getFlexCellFormatter().setStyleName(i + 1,
NUM_TRANS_COL, "txt--align-center");

if (i % 2 == 1) {
if (odd(i)) {
resultTable.getRowFormatter().setStyleName(i + 1, "oddRow");
}

Expand Down Expand Up @@ -348,6 +348,10 @@ public void onClick(ClickEvent event) {
}
}

private static boolean odd(int n) {
return n % 2 != 0;
}

@Override
public void redrawTable(List<TransMemoryResultItem> memories) {
for (int i = 0; i < memories.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public TabValidation(ValidationId id, ValidationMessages messages) {
super(id, messages.tabValidatorDesc(), messages);
}

@edu.umd.cs.findbugs.annotations.SuppressWarnings("GBU_GUAVA_BETA_CLASS_USAGE")
@Override
public List<String> doValidate(String source, String target) {
ArrayList<String> errors = new ArrayList<String>();

@edu.umd.cs.findbugs.annotations.SuppressWarnings("GBU_GUAVA_BETA_CLASS_USAGE")
CharMatcher tabs = CharMatcher.is('\t');
int sourceTabs = tabs.countIn(source);
int targetTabs = tabs.countIn(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
# SCRIPT Embedded scripting language - pass to another extractor
# SERVER Embedded server language tags such as JSP, PHP, Mason etc.
# ATTRIBUTE_TRANS, ATTRIBUTE_WRITABLE, ATTRIBUTE_READONLY, ATTRIBUTE_ID these rules list an attribute, not an element
# ATTRIBUTES_ONLY only attribute is translatable or localizable
# ATTRIBUTES_ONLY only attribute is translatable or localizable

#*********************************************************************************************
#*********************************************************************************************
# Operators for attribute value compare
#
# Rules are of the form:
# Rules are of the form:
# TO_EXTRACT_ATTRIBUTE:[IF_HAS_ATTRIBUTE, OPERATOR, VALUE]
# 'content':['http-equiv', EQUALS, 'keywords']
#
Expand All @@ -23,12 +23,12 @@
# Multiple attribute values may be included in a list:
# 'content':['http-equiv', EQUALS, ['content-language', 'content-type']]
#
# This rule would be read:
# extract the value of 'content' if the value of 'http-equiv' equals 'content-language' or 'content-type'
# This rule would be read:
# extract the value of 'content' if the value of 'http-equiv' equals 'content-language' or 'content-type'
#*******************************************************************************************/

# EQUALS
# NOT_EQUALS
# NOT_EQUALS
# MATCH regex match. Must match the entire attribute value

# ELEMENT AND ATTRIBUTE NAMES MUST BE LOWER CASED!!!!!!
Expand Down Expand Up @@ -61,7 +61,7 @@ attributes:
elements:
# only attributes are localizable or translatable - no PCDATA
# ATTRIBUTES_ONLY with translatableAttributes implies the tag will be a TEXTUNIT
# with embedded skeleton
# with embedded skeleton
meta:
ruleTypes: [ATTRIBUTES_ONLY]
translatableAttributes: {content: [[http-equiv, EQUALS, keywords], [name, EQUALS, [keywords, description]]]}
Expand Down Expand Up @@ -124,7 +124,7 @@ elements:

li:
ruleTypes: [TEXTUNIT]
translatableAttributes: [value]
translatableAttributes: [value]
idAttributes: [id]

marquee:
Expand Down Expand Up @@ -233,10 +233,10 @@ elements:

input:
ruleTypes: [INLINE]
translatableAttributes:
alt: [type, NOT_EQUALS, [file, hidden, image, Password]]
value: [type, NOT_EQUALS, [file, hidden, image, Password]]
accesskey: [type, NOT_EQUALS, [file, hidden, image, Password]]
translatableAttributes:
alt: [type, NOT_EQUALS, [file, hidden, image, Password]]
value: [type, NOT_EQUALS, [file, hidden, image, Password]]
accesskey: [type, NOT_EQUALS, [file, hidden, image, Password]]
title: [type, NOT_EQUALS, [file, hidden, image, Password]]
placeholder: null

Expand Down Expand Up @@ -371,4 +371,4 @@ elements:

# javascript etc.
script:
ruleTypes: [EXCLUDE]
ruleTypes: [EXCLUDE]
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,3 @@ function registerMouseEvent(autocompleteId, selectItemAction,
function filterList(input, filterFn) {
filterFn(jQuery(input).val());
}

0 comments on commit 1f3f7bf

Please sign in to comment.