Permalink
Browse files

Put back @SuppressFBWarnings annotations, but filter them out in the …

…Ant build. This works with source code preprocessing with regular expressions, which is ugly, but is still better than losing the annotations in the IDE.

Revert "Removed FindBugs @SuppressFBWarnings annotations as they have caused warnings when compiling dependant code with Gradle."

This reverts commit 174c2b9.
  • Loading branch information...
1 parent 5ab3895 commit 4a4080918014790873f5f3f12b22a6460362c42a ddekany committed May 24, 2016
View
@@ -212,8 +212,27 @@
-->Java 6: ${boot.classpath.j2se1.6}<!--
--></echo>
- <mkdir dir="build/classes" />
+ <!-- Comment out @SuppressFBWarnings, as it causes compilation warnings in dependent Gradle projects -->
+ <delete dir="build/src-main-java-filtered" />
+ <mkdir dir="build/src-main-java-filtered" />
+ <copy toDir="build/src-main-java-filtered">
+ <fileset dir="src/main/java" />
+ </copy>
+ <replaceregexp
+ flags="gs" encoding="utf-8"
+ match='(@SuppressFBWarnings\(.+?"\s*\))' replace="/*\1*/"
+ >
+ <fileset dir="build/src-main-java-filtered" includes="**/*.java" />
+ </replaceregexp>
+ <replaceregexp
+ flags="gs" encoding="utf-8"
+ match='(import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;)' replace="// \1"
+ >
+ <fileset dir="build/src-main-java-filtered" includes="**/*.java" />
+ </replaceregexp>
+ <mkdir dir="build/classes" />
+
<!-- Note: the "build.base" conf doesn't include optional FreeMarker dependencies. -->
<ivy:cachepath conf="build.base" pathid="ivy.dep" />
<javac destdir="build/classes" deprecation="off"
@@ -232,13 +251,13 @@
freemarker/ext/ant/**"
>
<src>
- <pathelement location="src/main/java" />
+ <pathelement location="build/src-main-java-filtered" />
<pathelement location="build/generated-sources" />
</src>
</javac>
<ivy:cachepath conf="build.base" pathid="ivy.dep" />
- <javac srcdir="src/main/java" destdir="build/classes" deprecation="off"
+ <javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
includeantruntime="false"
classpathref="ivy.dep"
@@ -253,7 +272,7 @@
/>
<ivy:cachepath conf="build.jsp2.0" pathid="ivy.dep.jsp2.0" />
- <javac srcdir="src/main/java" destdir="build/classes" deprecation="off"
+ <javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
includeantruntime="false"
classpathref="ivy.dep.jsp2.0"
@@ -271,7 +290,7 @@
<!-- There's no build.jsp2.0, as those classes are part of the common build subset. -->
<ivy:cachepath conf="build.jsp2.1" pathid="ivy.dep.jsp2.1" />
- <javac srcdir="src/main/java" destdir="build/classes" deprecation="off"
+ <javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
includeantruntime="false"
classpathref="ivy.dep.jsp2.1"
@@ -283,7 +302,7 @@
/>
<ivy:cachepath conf="build.jython2.0" pathid="ivy.dep.jython2.0" />
- <javac srcdir="src/main/java" destdir="build/classes" deprecation="off"
+ <javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
includeantruntime="false"
classpathref="ivy.dep.jython2.0"
@@ -298,7 +317,7 @@
/>
<ivy:cachepath conf="build.jython2.2" pathid="ivy.dep.jython2.2" />
- <javac srcdir="src/main/java" destdir="build/classes" deprecation="off"
+ <javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
includeantruntime="false"
classpathref="ivy.dep.jython2.2"
@@ -308,7 +327,7 @@
/>
<ivy:cachepath conf="build.jython2.5" pathid="ivy.dep.jython2.5" />
- <javac srcdir="src/main/java" destdir="build/classes" deprecation="off"
+ <javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
includeantruntime="false"
classpathref="ivy.dep.jython2.5"
@@ -318,7 +337,7 @@
/>
<rmic base="build/classes" classpathref="ivy.dep"
- includes="src/main/java/freemarker/debug/impl/Rmi*Impl.class"
+ includes="build/src-main-java-filtered/freemarker/debug/impl/Rmi*Impl.class"
verify="yes" stubversion="1.2"
/>
View
@@ -132,8 +132,8 @@
<dependency org="org.zeroturnaround" name="javarebel-sdk" rev="1.2.2" conf="build.base->default" />
- <!-- This was removed as @SuppressFBWarnings causes compilation warning in dependant Gradle projects -->
- <!-- dependency org="com.google.code.findbugs" name="annotations" rev="3.0.0" conf="build.base->default" /-->
+ <!-- Not for build.base, as @SuppressFBWarnings causes compilation warnings in dependent Gradle projects -->
+ <dependency org="com.google.code.findbugs" name="annotations" rev="3.0.0" conf="IDE->default; test->default" />
<!--dependency org="javax.script" name="script-api" rev="1.0" conf="build.base->default" /-->
<!--dependency org="org.visigoths" name="cavalry" rev="1.0" conf="build.base->default" /-->
@@ -104,8 +104,8 @@ private BuiltInsForNodes() { }
static class AncestorSequence extends SimpleSequence implements TemplateMethodModel {
- // @SuppressFBWarnings(value="SE_BAD_FIELD",
- // justification="Can't make this Serializable, and not extneding SimpleSequence would be non-BC.")
+ @SuppressFBWarnings(value="SE_BAD_FIELD",
+ justification="Can't make this Serializable, and not extneding SimpleSequence would be non-BC.")
private Environment env;
AncestorSequence(Environment env) {
@@ -250,7 +250,7 @@ public Template getMainTemplate() {
*
* @since 2.3.23
*/
- // @SuppressFBWarnings(value = "RANGE_ARRAY_INDEX", justification = "False alarm")
+ @SuppressFBWarnings(value = "RANGE_ARRAY_INDEX", justification = "False alarm")
public Template getCurrentTemplate() {
int ln = instructionStackSize;
return ln == 0 ? getMainTemplate() : instructionStack[ln - 1].getTemplate();
@@ -264,7 +264,7 @@ public Template getCurrentTemplate() {
*
* @since 2.3.22
*/
- // @SuppressFBWarnings(value = "RANGE_ARRAY_INDEX", justification = "False alarm")
+ @SuppressFBWarnings(value = "RANGE_ARRAY_INDEX", justification = "False alarm")
public DirectiveCallPlace getCurrentDirectiveCallPlace() {
int ln = instructionStackSize;
if (ln == 0) return null;
@@ -377,7 +377,7 @@ final void visit(TemplateElement[] elementBuffer) throws IOException, TemplateEx
}
}
- // @SuppressFBWarnings(value = "RANGE_ARRAY_INDEX", justification = "Not called when stack is empty")
+ @SuppressFBWarnings(value = "RANGE_ARRAY_INDEX", justification = "Not called when stack is empty")
private TemplateElement replaceTopElement(TemplateElement element) {
return instructionStack[instructionStackSize - 1] = element;
}
@@ -198,8 +198,8 @@ protected abstract String format(Date date,
DateToISO8601CalendarFactory calendarFactory);
@Override
- // @SuppressFBWarnings(value = "RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN",
- // justification = "Known to use the singleton Boolean-s only")
+ @SuppressFBWarnings(value = "RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN",
+ justification = "Known to use the singleton Boolean-s only")
public final Date parse(String s, int dateType) throws UnparsableValueException {
CalendarFieldsToDateConverter calToDateConverter = factory.getCalendarFieldsToDateCalculator(env);
TimeZone tz = forceUTC != Boolean.FALSE ? DateUtil.UTC : timeZone;
@@ -249,7 +249,7 @@ ParameterRole getParameterRole(int idx) {
return res;
}
- // @SuppressFBWarnings(value={ "IS2_INCONSISTENT_SYNC", "DC_DOUBLECHECK" }, justification="Performance tricks")
+ @SuppressFBWarnings(value={ "IS2_INCONSISTENT_SYNC", "DC_DOUBLECHECK" }, justification="Performance tricks")
public Object getOrCreateCustomData(Object providerIdentity, ObjectFactory objectFactory)
throws CallPlaceCustomDataInitializationException {
// We are using double-checked locking, utilizing Java memory model "final" trick.
@@ -106,7 +106,7 @@ static synchronized Object getCachedWrapperFor(Object key)
}
// TODO See in SuppressFBWarnings
- // @SuppressFBWarnings(value="NN_NAKED_NOTIFY", justification="Will have to be re-desigend; postponed.")
+ @SuppressFBWarnings(value="NN_NAKED_NOTIFY", justification="Will have to be re-desigend; postponed.")
public void resume() {
synchronized (this) {
notify();
@@ -93,8 +93,7 @@ List getBreakpointsSpi() {
// TODO See in SuppressFBWarnings
@Override
- // @SuppressFBWarnings(value={ "UW_UNCOND_WAIT", "WA_NOT_IN_LOOP" },
- // justification="Will have to be re-desigend; postponed.")
+ @SuppressFBWarnings(value={ "UW_UNCOND_WAIT", "WA_NOT_IN_LOOP" }, justification="Will have to be re-desigend; postponed.")
boolean suspendEnvironmentSpi(Environment env, String templateName, int line)
throws RemoteException {
RmiDebuggedEnvironmentImpl denv =
@@ -45,8 +45,7 @@ protected boolean isCacheable(Object object) {
}
@Override
- // @SuppressFBWarnings(value="JLM_JSR166_UTILCONCURRENT_MONITORENTER",
- // justification="Locks for factory creation only")
+ @SuppressFBWarnings(value="JLM_JSR166_UTILCONCURRENT_MONITORENTER", justification="Locks for factory creation only")
protected TemplateModel create(Object object) {
Class clazz = object.getClass();
@@ -133,8 +133,8 @@ void addCallableMemberDescriptor(ReflectionCallableMemberDescriptor memberDesc)
return unwrappingHintsByParamCount;
}
- // @SuppressFBWarnings(value="JLM_JSR166_UTILCONCURRENT_MONITORENTER",
- // justification="Locks for member descriptor creation only")
+ @SuppressFBWarnings(value="JLM_JSR166_UTILCONCURRENT_MONITORENTER",
+ justification="Locks for member descriptor creation only")
final MaybeEmptyCallableMemberDescriptor getMemberDescriptorForArgs(Object[] args, boolean varArg) {
ArgumentTypes argTypes = new ArgumentTypes(args, bugfixed);
MaybeEmptyCallableMemberDescriptor memberDesc
@@ -511,24 +511,24 @@
@Deprecated
protected boolean debug;
- // @SuppressFBWarnings(value="SE_BAD_FIELD", justification="Not investing into making this Servlet serializable")
+ @SuppressFBWarnings(value="SE_BAD_FIELD", justification="Not investing into making this Servlet serializable")
private Configuration config;
- // @SuppressFBWarnings(value="SE_BAD_FIELD", justification="Not investing into making this Servlet serializable")
+ @SuppressFBWarnings(value="SE_BAD_FIELD", justification="Not investing into making this Servlet serializable")
private ObjectWrapper wrapper;
private ContentType contentType;
private OverrideResponseContentType overrideResponseContentType = initParamValueToEnum(
getDefaultOverrideResponseContentType(), OverrideResponseContentType.values());
private ResponseCharacterEncoding responseCharacterEncoding = ResponseCharacterEncoding.LEGACY;
- // @SuppressFBWarnings(value="SE_BAD_FIELD", justification="Not investing into making this Servlet serializable")
+ @SuppressFBWarnings(value="SE_BAD_FIELD", justification="Not investing into making this Servlet serializable")
private Charset forcedResponseCharacterEncoding;
private OverrideResponseLocale overrideResponseLocale = OverrideResponseLocale.ALWAYS;
private List/*<MetaInfTldSource>*/ metaInfTldSources;
private List/*<String>*/ classpathTlds;
private Object lazyInitFieldsLock = new Object();
- // @SuppressFBWarnings(value="SE_BAD_FIELD", justification="Not investing into making this Servlet serializable")
+ @SuppressFBWarnings(value="SE_BAD_FIELD", justification="Not investing into making this Servlet serializable")
private ServletContextHashModel servletContextModel;
- // @SuppressFBWarnings(value="SE_BAD_FIELD", justification="Not investing into making this Servlet serializable")
+ @SuppressFBWarnings(value="SE_BAD_FIELD", justification="Not investing into making this Servlet serializable")
private TaglibFactory taglibFactory;
private boolean objectWrapperMismatchWarnLogged;
@@ -956,7 +956,7 @@ private ServletException newServletExceptionWithFreeMarkerLogging(String message
throw e;
}
- // @SuppressFBWarnings(value={ "MSF_MUTABLE_SERVLET_FIELD", "DC_DOUBLECHECK" }, justification="Performance trick")
+ @SuppressFBWarnings(value={ "MSF_MUTABLE_SERVLET_FIELD", "DC_DOUBLECHECK" }, justification="Performance trick")
private void logWarnOnObjectWrapperMismatch() {
// Deliberately uses double check locking.
if (wrapper != config.getObjectWrapper() && !objectWrapperMismatchWarnLogged && LOG.isWarnEnabled()) {
@@ -43,7 +43,7 @@
public class DefaultIteratorAdapter extends WrappingTemplateModel implements TemplateCollectionModel,
AdapterTemplateModel, WrapperTemplateModel, Serializable {
- // @SuppressFBWarnings(value="SE_BAD_FIELD", justification="We hope it's Seralizable")
+ @SuppressFBWarnings(value="SE_BAD_FIELD", justification="We hope it's Seralizable")
private final Iterator iterator;
private boolean iteratorOwnedBySomeone;
@@ -39,7 +39,7 @@
*
* @see Configuration#setObjectWrapper(ObjectWrapper)
*/
-// @SuppressFBWarnings(value="IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION", justification="BC")
+@SuppressFBWarnings(value="IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION", justification="BC")
public interface ObjectWrapper {
/**
@@ -215,7 +215,7 @@ public Template(
* {@code null}. This is useful as the {@link Configuration} is normally a singleton shared by all
* templates, and so it's not good for specifying template-specific settings. (While {@link Template}
* itself has methods to specify settings just for that template, those don't influence the parsing, and
- * you only have opportunity to call them after the parsing anyway.) This object is often a
+ * you only have opportunity to call them after the parsing anyway.) This objects is often a
* {@link TemplateConfiguration} whose parent is the {@link Configuration} parameter, and then it
* practically just overrides some of the parser settings, as the others are inherited from the
* {@link Configuration}. Note that if this is a {@link TemplateConfiguration}, you will also want to
@@ -33,7 +33,6 @@ import freemarker.template.*;
import freemarker.template.utility.*;
import java.io.*;
import java.util.*;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* This class is generated by JavaCC from a grammar file.
@@ -26562,8 +26562,10 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
<listitem>
<para>Removed FindBugs <literal>@SuppressFBWarnings</literal>
- annotations as they have caused warnings when compiling
- dependant code with Gradle.</para>
+ annotations from the binary (<literal>freemarker.jar</literal>),
+ as they have caused warnings like this when compiling dependant
+ project with Gradle: <quote>warning: Cannot find annotation
+ method 'value()' in type 'SuppressFBWarnings'</quote></para>
</listitem>
</itemizedlist>
</section>
@@ -1183,7 +1183,7 @@ public void testTimeZoneLayers() throws TemplateException, IOException {
assertEquals("null", env2.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY));
}
- // @SuppressFBWarnings(value="NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS", justification="Expected to fail")
+ @SuppressFBWarnings(value="NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS", justification="Expected to fail")
private void setTimeZoneToNull(Environment env2) {
env2.setTimeZone(null);
}
@@ -1306,7 +1306,7 @@ public void testTemplateUpdateDelay() throws IOException, TemplateException {
}
@Test
- // @SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS ", justification = "Testing wrong args")
+ @SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS ", justification = "Testing wrong args")
public void testSetCustomNumberFormat() throws Exception {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
@@ -1431,7 +1431,7 @@ public void testTabSizeSetting() throws Exception {
}
}
- // @SuppressFBWarnings(value="NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS", justification="We test failures")
+ @SuppressFBWarnings(value="NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS", justification="We test failures")
@Test
public void testSetCustomDateFormat() throws Exception {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
@@ -81,7 +81,7 @@ protected void assertOutputForNamed(String name, String expectedOut) throws IOEx
assertOutput(getConfiguration().getTemplate(name), expectedOut, false);
}
- // @SuppressFBWarnings(value="UI_INHERITANCE_UNSAFE_GETRESOURCE", justification="By design relative to subclass")
+ @SuppressFBWarnings(value="UI_INHERITANCE_UNSAFE_GETRESOURCE", justification="By design relative to subclass")
protected void assertOutputForNamed(String name) throws IOException, TemplateException {
String expectedOut;
{
@@ -261,7 +261,7 @@ private static void deleteTemporaryDirectories() throws IOException {
}
}
- // @SuppressFBWarnings(value = "UI_INHERITANCE_UNSAFE_GETRESOURCE", justification = "By design relative to subclass")
+ @SuppressFBWarnings(value = "UI_INHERITANCE_UNSAFE_GETRESOURCE", justification = "By design relative to subclass")
private String createWebAppDirAndGetURI(String webAppName) throws IOException {
ClassPathResource resourceDir = findWebAppDirectoryResource(webAppName);
File temporaryDir = ResourcesExtractor.extract(
@@ -137,7 +137,7 @@ protected File getActualFileDirectory() throws IOException {
return getExpectedFileDirectory();
}
- // @SuppressFBWarnings(value="UI_INHERITANCE_UNSAFE_GETRESOURCE", justification="By design relative to subclass")
+ @SuppressFBWarnings(value="UI_INHERITANCE_UNSAFE_GETRESOURCE", justification="By design relative to subclass")
protected final File getTestClassDirectory() throws IOException {
URL url = this.getClass().getResource(".");
if (url == null) throw new IOException("Couldn't get resource URL for \".\"");

0 comments on commit 4a40809

Please sign in to comment.