Skip to content

Commit 42e7d5f

Browse files
committed
IDE warning cleanup
1 parent 069a0df commit 42e7d5f

25 files changed

+229
-92
lines changed

src/main/java/org/owasp/html/AttributePolicy.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* A policy that can be applied to an HTML attribute to decide whether or not to
4141
* allow it in the output, possibly after transforming its value.
4242
*
43-
* @author Mike Samuel <[email protected]>
43+
* @author Mike Samuel ([email protected])
4444
* @see HtmlPolicyBuilder.AttributeBuilder#matching(AttributePolicy)
4545
*/
4646
@TCB public interface AttributePolicy {
@@ -88,7 +88,7 @@ public static final AttributePolicy join(AttributePolicy... policies) {
8888
}
8989
}
9090

91-
91+
/** An attribute policy that returns the value unchanged. */
9292
public static final AttributePolicy IDENTITY_ATTRIBUTE_POLICY
9393
= new AttributePolicy() {
9494
public String apply(
@@ -97,6 +97,7 @@ public String apply(
9797
}
9898
};
9999

100+
/** An attribute policy that rejects all values. */
100101
public static final AttributePolicy REJECT_ALL_ATTRIBUTE_POLICY
101102
= new AttributePolicy() {
102103
public @Nullable String apply(
@@ -116,7 +117,8 @@ final class JoinedAttributePolicy implements AttributePolicy {
116117
}
117118

118119
public @Nullable String apply(
119-
String elementName, String attributeName, @Nullable String value) {
120+
String elementName, String attributeName, @Nullable String rawValue) {
121+
String value = rawValue;
120122
for (AttributePolicy p : policies) {
121123
if (value == null) { break; }
122124
value = p.apply(elementName, attributeName, value);

src/main/java/org/owasp/html/CssGrammar.java

+5
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ static String cssContent(String token) {
180180
try {
181181
codepoint = Integer.parseInt(token.substring(esc + 1, end), 16);
182182
} catch (RuntimeException ex) {
183+
ignore(ex);
183184
codepoint = 0xfffd; // Unknown codepoint.
184185
}
185186
if (end < n) {
@@ -215,4 +216,8 @@ interface PropertyHandler {
215216
void endProperty();
216217
}
217218

219+
/** @param o ignored */
220+
private static void ignore(Object o) {
221+
// Do nothing
222+
}
218223
}

src/main/java/org/owasp/html/CssSchema.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static final class Property {
5353
*/
5454
final ImmutableMap<String, String> fnKeys;
5555

56-
private Property(
56+
Property(
5757
int bits, ImmutableSet<String> literals,
5858
ImmutableMap<String, String> fnKeys) {
5959
this.bits = bits;
@@ -126,13 +126,13 @@ public Set<String> allowedProperties() {
126126

127127
/** The schema for the named property or function key. */
128128
Property forKey(String propertyName) {
129-
propertyName = Strings.toLowerCase(propertyName);
130-
Property property = properties.get(propertyName);
129+
String propertyNameCanon = Strings.toLowerCase(propertyName);
130+
Property property = properties.get(propertyNameCanon);
131131
if (property != null) { return property; }
132-
int n = propertyName.length();
133-
if (n != 0 && propertyName.charAt(0) == '-') {
134-
String barePropertyName = stripVendorPrefix(propertyName);
135-
property = properties.get(barePropertyName);
132+
int n = propertyNameCanon.length();
133+
if (n != 0 && propertyNameCanon.charAt(0) == '-') {
134+
String barePropertyNameCanon = stripVendorPrefix(propertyNameCanon);
135+
property = properties.get(barePropertyNameCanon);
136136
if (property != null) { return property; }
137137
}
138138
return DISALLOWED;

src/main/java/org/owasp/html/CssTokens.java

+21-3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public static CssTokens lex(String css) {
8989
}
9090

9191
/** A cursor into a list of tokens. */
92+
@SuppressWarnings("synthetic-access")
9293
public final class TokenIterator implements Iterator<String> {
9394
private int tokenIndex = 0;
9495
private final int limit;
@@ -152,8 +153,8 @@ public TokenType type() {
152153
return tokenTypes[tokenIndex];
153154
}
154155

155-
public void seek(int tokenIndex) {
156-
this.tokenIndex = tokenIndex;
156+
public void seek(int newTokenIndex) {
157+
this.tokenIndex = newTokenIndex;
157158
}
158159

159160
public void advance() {
@@ -249,7 +250,7 @@ static final class Brackets {
249250
*/
250251
private final int[] brackets;
251252

252-
private Brackets(int[] brackets) {
253+
Brackets(int[] brackets) {
253254
this.brackets = brackets;
254255
}
255256

@@ -290,6 +291,7 @@ int bracketIndexForToken(int target) {
290291
/**
291292
* Tokenizes according to section 4 of http://dev.w3.org/csswg/css-syntax/
292293
*/
294+
@SuppressWarnings("synthetic-access")
293295
private static final class Lexer {
294296
private final String css;
295297
private final StringBuilder sb;
@@ -427,7 +429,9 @@ void lex() {
427429

428430
tokenTypes = new ArrayList<TokenType>();
429431

432+
@SuppressWarnings("hiding") // final
430433
String css = this.css;
434+
@SuppressWarnings("hiding") // final
431435
int cssLimit = this.cssLimit;
432436
while (pos < cssLimit) {
433437
assert this.tokenBreaksLimit == this.tokenTypes.size()
@@ -687,7 +691,9 @@ private void consumeDelim(char ch) {
687691
}
688692

689693
private boolean consumeIgnorable() {
694+
@SuppressWarnings("hiding") // final
690695
String css = this.css;
696+
@SuppressWarnings("hiding") // final
691697
int cssLimit = this.cssLimit;
692698
int posBefore = pos;
693699
while (pos < cssLimit) {
@@ -772,6 +778,7 @@ private void consumeMatch(char ch) {
772778
}
773779

774780
private void consumeIdent(boolean allowFirstDigit) {
781+
@SuppressWarnings("hiding") // final
775782
int cssLimit = this.cssLimit;
776783
int last = -1, nCodepoints = 0;
777784
int sbAtStart = sb.length();
@@ -824,7 +831,9 @@ private boolean consumeAtKeyword() {
824831

825832

826833
private int consumeAndDecodeEscapeSequence() {
834+
@SuppressWarnings("hiding") // final
827835
String css = this.css;
836+
@SuppressWarnings("hiding") // final
828837
int cssLimit = this.cssLimit;
829838
assert css.charAt(pos) == '\\';
830839
if (pos + 1 >= cssLimit) { return -1; }
@@ -907,7 +916,9 @@ private void encodeCharOntoOutput(int codepoint, int last) {
907916
}
908917

909918
private TokenType consumeNumberOrPercentageOrDimension() {
919+
@SuppressWarnings("hiding") // final
910920
String css = this.css;
921+
@SuppressWarnings("hiding") // final
911922
int cssLimit = this.cssLimit;
912923
boolean isZero = true;
913924
int intStart = pos;
@@ -1057,7 +1068,9 @@ private TokenType consumeNumberOrPercentageOrDimension() {
10571068
}
10581069

10591070
private TokenType consumeString() {
1071+
@SuppressWarnings("hiding") // final
10601072
String css = this.css;
1073+
@SuppressWarnings("hiding") // final
10611074
int cssLimit = this.cssLimit;
10621075

10631076
char delim = css.charAt(pos);
@@ -1129,7 +1142,9 @@ private TokenType consumeString() {
11291142
}
11301143

11311144
private boolean consumeUnicodeRange() {
1145+
@SuppressWarnings("hiding") // final
11321146
final String css = this.css;
1147+
@SuppressWarnings("hiding") // final
11331148
final int cssLimit = this.cssLimit;
11341149

11351150
assert pos < cssLimit && (css.charAt(pos) | 32) == 'u';
@@ -1246,7 +1261,9 @@ private boolean consumeUnicodeRange() {
12461261
}
12471262

12481263
private boolean consumeUrlValue() {
1264+
@SuppressWarnings("hiding") // final
12491265
String css = this.css;
1266+
@SuppressWarnings("hiding") // final
12501267
int cssLimit = this.cssLimit;
12511268
if (pos == cssLimit || css.charAt(pos) != '(') { return false; }
12521269
++pos;
@@ -1355,6 +1372,7 @@ private boolean consumeUrlValue() {
13551372
* unit.
13561373
*/
13571374
private int readCodepoint() {
1375+
@SuppressWarnings("hiding") // final
13581376
String css = this.css;
13591377
char ch = css.charAt(pos);
13601378
if (Character.isHighSurrogate(ch) && pos + 1 < cssLimit) {

src/main/java/org/owasp/html/ElementAndAttributePolicies.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
/**
3737
* Encapsulates all the information needed by the
38-
* {@link ElementAndAttributePolicyBasedSanitizerPolicy} to sanitize one kind
38+
* {@link ElementAndAttributePolicySanitizerPolicy} to sanitize one kind
3939
* of element.
4040
*/
4141
@Immutable

src/main/java/org/owasp/html/ElementPolicy.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* {@link AttributePolicy attribute policies} so
4242
* they can be used to add extra attributes.
4343
*
44-
* @author Mike Samuel <[email protected]>
44+
* @author Mike Samuel ([email protected])
4545
* @see HtmlPolicyBuilder#allowElements(ElementPolicy, String...)
4646
*/
4747
@TCB public interface ElementPolicy {
@@ -100,13 +100,15 @@ void join(ElementPolicy p) {
100100

101101
}
102102

103+
/** An element policy that returns the element unchanged. */
103104
public static final ElementPolicy IDENTITY_ELEMENT_POLICY
104105
= new ElementPolicy() {
105106
public String apply(String elementName, List<String> attrs) {
106107
return elementName;
107108
}
108109
};
109110

111+
/** An element policy that rejects all elements. */
110112
public static final ElementPolicy REJECT_ALL_ELEMENT_POLICY
111113
= new ElementPolicy() {
112114
public @Nullable String apply(String elementName, List<String> attrs) {
@@ -126,7 +128,9 @@ final class JoinedElementPolicy implements ElementPolicy {
126128
}
127129

128130
public @Nullable String apply(String elementName, List<String> attrs) {
129-
elementName = first.apply(elementName, attrs);
130-
return elementName != null ? second.apply(elementName, attrs) : null;
131+
String filteredElementName = first.apply(elementName, attrs);
132+
return filteredElementName != null
133+
? second.apply(filteredElementName, attrs)
134+
: null;
131135
}
132136
}

src/main/java/org/owasp/html/FilterUrlByProtocolAttributePolicy.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@
5252
* do not look like they contain an authority portion.
5353
* </p>
5454
*
55-
* @author Mike Samuel <[email protected]>
55+
* @author Mike Samuel ([email protected])
5656
*/
5757
@TCB
5858
public class FilterUrlByProtocolAttributePolicy implements AttributePolicy {
5959
private final ImmutableSet<String> protocols;
6060

61+
/**
62+
* @param protocols lower-case protocol names without any trailing colon (":")
63+
*/
6164
public FilterUrlByProtocolAttributePolicy(
6265
Iterable<? extends String> protocols) {
6366
this.protocols = ImmutableSet.copyOf(protocols);

src/main/java/org/owasp/html/Handler.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@
3333
/**
3434
* Receives notification of problems.
3535
*
36-
* @author Mike Samuel <[email protected]>
36+
* @param <T> the type of the problem.
37+
* @author Mike Samuel ([email protected])
3738
*/
3839
public interface Handler<T> {
3940

41+
/**
42+
* Called to handle x.
43+
* @param x the problem.
44+
*/
4045
void handle(T x);
4146

4247
/** A handler that does nothing given any input. */

src/main/java/org/owasp/html/HtmlChangeReporter.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public final class HtmlChangeReporter<T> {
5555
private final OutputChannel output;
5656
private final InputChannel<T> input;
5757

58+
/**
59+
* @param context forwarded to listener along with any reports.
60+
*/
5861
public HtmlChangeReporter(
5962
HtmlStreamEventReceiver renderer,
6063
HtmlChangeListener<? super T> listener, @Nullable T context) {
@@ -70,8 +73,14 @@ public void setPolicy(HtmlSanitizer.Policy policy) {
7073
this.input.policy = policy;
7174
}
7275

76+
/**
77+
* The underlying renderer.
78+
*/
7379
public HtmlStreamEventReceiver getWrappedRenderer() { return output; }
7480

81+
/**
82+
* The underlying policy.
83+
*/
7584
public HtmlSanitizer.Policy getWrappedPolicy() { return input; }
7685

7786
private static final class InputChannel<T> implements HtmlSanitizer.Policy {
@@ -133,6 +142,8 @@ public void closeTag(String elementName) {
133142
public void text(String textChunk) {
134143
policy.text(textChunk);
135144
}
145+
146+
private static final String[] ZERO_STRINGS = new String[0];
136147
}
137148

138149
private static final class OutputChannel implements HtmlStreamEventReceiver {
@@ -170,6 +181,4 @@ public void text(String text) {
170181
renderer.text(text);
171182
}
172183
}
173-
174-
private static final String[] ZERO_STRINGS = new String[0];
175184
}

src/main/java/org/owasp/html/HtmlLexer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* A flexible lexer for HTML.
4141
* This is hairy code, but it is outside the TCB for the HTML sanitizer.
4242
*
43-
* @author Mike Samuel <[email protected]>
43+
* @author Mike Samuel ([email protected])
4444
*/
4545
@NotThreadSafe
4646
final class HtmlLexer extends AbstractTokenStream {
@@ -440,7 +440,7 @@ private HtmlToken parseToken() {
440440
} else if ('"' == ch || '\'' == ch) {
441441
if (end + 1 < limit) {
442442
char ch2 = input.charAt(end + 1);
443-
if (ch2 >= 0 && Character.isWhitespace(ch2)
443+
if (Character.isWhitespace(ch2)
444444
|| ch2 == '>' || ch2 == '/') {
445445
++end;
446446
break;
@@ -710,7 +710,7 @@ static HtmlToken reclassify(HtmlToken token, HtmlTokenType type) {
710710
/**
711711
* A TokenStream that lazily fetches one token at a time.
712712
*
713-
* @author Mike Samuel <[email protected]>
713+
* @author Mike Samuel ([email protected])
714714
*/
715715
abstract class AbstractTokenStream implements TokenStream {
716716
private HtmlToken tok;

0 commit comments

Comments
 (0)