Skip to content

Commit e4d4aad

Browse files
committed
Fixed potential NPE and refactored some code.
1 parent dc6f513 commit e4d4aad

File tree

61 files changed

+796
-1136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+796
-1136
lines changed

modules/org.restlet.ext.apispark/src/org/restlet/ext/apispark/Introspector.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static void process(String[] args) throws TranslationException {
129129
Engine.register();
130130
String ulogin = null;
131131
String upwd = null;
132-
String serviceUrl = null;
132+
String serviceUrl = "https://apispark.restlet.com/";
133133
String defSource = null;
134134
String compName = null;
135135
String language = null;
@@ -251,9 +251,6 @@ public static void process(String[] args) throws TranslationException {
251251
+ " is not currently supported. ");
252252
}
253253

254-
if (StringUtils.isNullOrEmpty(serviceUrl)) {
255-
serviceUrl = "https://apispark.restlet.com/";
256-
}
257254
if (!serviceUrl.endsWith("/")) {
258255
serviceUrl += "/";
259256
}

modules/org.restlet.ext.apispark/src/org/restlet/ext/apispark/internal/agent/module/AnalyticsHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public void run() {
283283
*/
284284
private long getRetryTime(int attemptNumber) {
285285
long newTime = RETRY_AFTER
286-
* ((int) Math.pow(2.0, attemptNumber - 1));
286+
* ((int) Math.pow(2.0d, attemptNumber - 1));
287287
return Math.min(newTime, MAX_TIME);
288288
}
289289
}

modules/org.restlet.ext.crypto/src/org/restlet/ext/crypto/internal/HttpDigestVerifier.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ public int verify(Request request, Response response) {
113113
result = RESULT_MISSING;
114114
} else {
115115
String nonce = cr.getServerNonce();
116-
String uri = (cr.getDigestRef() == null) ? null : cr.getDigestRef()
117-
.toString();
116+
String uri = (cr.getDigestRef() == null) ? null : cr.getDigestRef().toString();
118117
String qop = cr.getQuality();
119118
int nc = cr.getServerNounceCount();
120119
String cnonce = cr.getClientNonce();

modules/org.restlet.ext.gwt/src/org/restlet/ext/gwt/GwtConverter.java

+53-64
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
package org.restlet.ext.gwt;
2626

27+
import static org.restlet.data.MediaType.APPLICATION_JAVA_OBJECT_GWT;
28+
2729
import java.io.IOException;
2830
import java.io.Serializable;
2931
import java.util.List;
@@ -47,8 +49,7 @@
4749
public class GwtConverter extends ConverterHelper {
4850

4951
/** GWT variant. */
50-
private static final VariantInfo VARIANT_GWT = new VariantInfo(
51-
MediaType.APPLICATION_JAVA_OBJECT_GWT);
52+
private static final VariantInfo VARIANT_GWT = new VariantInfo(APPLICATION_JAVA_OBJECT_GWT);
5253

5354
@Override
5455
public List<Class<?>> getObjectClasses(Variant source) {
@@ -77,92 +78,81 @@ public List<VariantInfo> getVariants(Class<?> source) {
7778

7879
@Override
7980
public float score(Object source, Variant target, Resource resource) {
80-
float result = -1.0F;
8181

8282
if (source instanceof Serializable || source instanceof IsSerializable) {
8383
if (target == null) {
84-
result = 0.5F;
85-
} else if (MediaType.APPLICATION_JAVA_OBJECT_GWT.equals(target
86-
.getMediaType())) {
87-
result = 1.0F;
88-
} else if (MediaType.APPLICATION_JAVA_OBJECT_GWT
89-
.isCompatible(target.getMediaType())) {
90-
result = 0.6F;
91-
} else {
92-
result = 0.5F;
84+
return 0.5F;
85+
}
86+
if (APPLICATION_JAVA_OBJECT_GWT.equals(target.getMediaType())) {
87+
return 1.0F;
88+
}
89+
if (APPLICATION_JAVA_OBJECT_GWT.isCompatible(target.getMediaType())) {
90+
return 0.6F;
9391
}
92+
return 0.5F;
9493
}
9594

96-
return result;
95+
return -1.0F;
9796
}
9897

9998
@Override
100-
public <T> float score(Representation source, Class<T> target,
101-
Resource resource) {
102-
float result = -1.0F;
103-
99+
public <T> float score(Representation source, Class<T> target, Resource resource) {
104100
if (source instanceof ObjectRepresentation<?>) {
105-
result = 1.0F;
106-
} else if ((target != null)
107-
&& ObjectRepresentation.class.isAssignableFrom(target)) {
108-
result = 1.0F;
109-
} else if ((target != null)
110-
&& (Serializable.class.isAssignableFrom(target) || IsSerializable.class
111-
.isAssignableFrom(target))) {
112-
if (MediaType.APPLICATION_JAVA_OBJECT_GWT.equals(source
113-
.getMediaType())) {
114-
result = 1.0F;
115-
} else if (MediaType.APPLICATION_JAVA_OBJECT_GWT
116-
.isCompatible(source.getMediaType())) {
117-
result = 0.6F;
101+
return 1.0F;
102+
}
103+
104+
if (target != null) {
105+
if (ObjectRepresentation.class.isAssignableFrom(target)) {
106+
return 1.0F;
107+
}
108+
if (Serializable.class.isAssignableFrom(target)
109+
|| IsSerializable.class.isAssignableFrom(target)) {
110+
if (APPLICATION_JAVA_OBJECT_GWT.equals(source.getMediaType())) {
111+
return 1.0F;
112+
}
113+
if (APPLICATION_JAVA_OBJECT_GWT.isCompatible(source.getMediaType())) {
114+
return 0.6F;
115+
}
118116
}
119117
}
120118

121-
return result;
119+
return -1.0F;
122120
}
123121

124122
@SuppressWarnings("unchecked")
125123
@Override
126-
public <T> T toObject(Representation source, Class<T> target,
127-
Resource resource) throws IOException {
128-
ObjectRepresentation<?> gwtSource = null;
129-
if (source instanceof ObjectRepresentation<?>) {
130-
gwtSource = (ObjectRepresentation<?>) source;
131-
} else {
132-
gwtSource = new ObjectRepresentation<T>(source.getText(), target);
133-
}
124+
public <T> T toObject(Representation source, Class<T> target, Resource resource) throws IOException {
125+
ObjectRepresentation<?> gwtSource = (source instanceof ObjectRepresentation<?>) ?
126+
(ObjectRepresentation<?>) source :
127+
new ObjectRepresentation<T>(source.getText(), target);
134128

135-
T result = null;
136-
if (gwtSource != null) {
137-
if (target == null) {
138-
result = (T) gwtSource.getObject();
139-
} else if (ObjectRepresentation.class.isAssignableFrom(target)) {
140-
result = (T) gwtSource;
141-
} else if (Serializable.class.isAssignableFrom(target)
142-
|| IsSerializable.class.isAssignableFrom(target)) {
143-
result = (T) gwtSource.getObject();
144-
}
129+
if (target == null) {
130+
return (T) gwtSource.getObject();
131+
}
132+
if (ObjectRepresentation.class.isAssignableFrom(target)) {
133+
return (T) gwtSource;
134+
}
135+
if (Serializable.class.isAssignableFrom(target)
136+
|| IsSerializable.class.isAssignableFrom(target)) {
137+
return (T) gwtSource.getObject();
145138
}
146139

147-
return result;
140+
return null;
148141
}
149142

150143
@Override
151-
public Representation toRepresentation(Object source, Variant target,
152-
Resource resource) {
153-
Representation result = null;
154-
144+
public Representation toRepresentation(Object source, Variant target, Resource resource) {
155145
if (source instanceof Serializable) {
156-
result = new ObjectRepresentation<Serializable>(
157-
(Serializable) source);
158-
} else if (source instanceof IsSerializable) {
159-
result = new ObjectRepresentation<IsSerializable>(
160-
(IsSerializable) source);
161-
} else if (source instanceof Representation) {
162-
result = (Representation) source;
146+
return new ObjectRepresentation<Serializable>((Serializable) source);
147+
}
148+
if (source instanceof IsSerializable) {
149+
return new ObjectRepresentation<IsSerializable>((IsSerializable) source);
150+
}
151+
if (source instanceof Representation) {
152+
return (Representation) source;
163153
}
164154

165-
return result;
155+
return null;
166156
}
167157

168158
@Override
@@ -171,8 +161,7 @@ public <T> void updatePreferences(List<Preference<MediaType>> preferences,
171161
if (Serializable.class.isAssignableFrom(entity)
172162
|| IsSerializable.class.isAssignableFrom(entity)
173163
|| ObjectRepresentation.class.isAssignableFrom(entity)) {
174-
updatePreferences(preferences,
175-
MediaType.APPLICATION_JAVA_OBJECT_GWT, 1.0F);
164+
updatePreferences(preferences, APPLICATION_JAVA_OBJECT_GWT, 1.0F);
176165
}
177166
}
178167

modules/org.restlet.ext.jaas/src/org/restlet/ext/jaas/JaasVerifier.java

+9-16
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@
4242
* Verifier that leverages the JAAS pluggable authentication mechanism.
4343
*
4444
* @author Jerome Louvel
45-
* @see <a
46-
* href="http://download.oracle.com/javase/1.5.0/docs/guide/security/jaas/tutorials/index.html">JAAS
45+
* @see <a href="http://download.oracle.com/javase/1.5.0/docs/guide/security/jaas/tutorials/index.html">JAAS
4746
* Tutorials</a>
48-
* @see <a
49-
* href="http://download.oracle.com/javase/1.5.0/docs/guide/security/jaas/JAASRefGuide.html">JAAS
50-
* Reference Guide</a>
47+
* @see <a href="http://download.oracle.com/javase/1.5.0/docs/guide/security/jaas/JAASRefGuide.html">JAAS Reference
48+
* Guide</a>
5149
*/
5250
public class JaasVerifier implements Verifier {
5351

@@ -131,8 +129,8 @@ public void setName(String contextName) {
131129
/**
132130
* Sets the user principal class name. If a {@link User} is not associated
133131
* with the {@link Request}'s {@link ClientInfo} and if one of the
134-
* principals returned after the JAAS login is of this type, a new
135-
* {@link User} will be associated with the {@link ClientInfo} using its
132+
* principals returned after the JAAS login is of this type, a new {@link User} will be associated with the
133+
* {@link ClientInfo} using its
136134
* name.
137135
*
138136
* @param userPrincipalClassName
@@ -180,10 +178,8 @@ public int verify(Request request, Response response) {
180178
*/
181179
for (Principal principal : subject.getPrincipals()) {
182180
if ((!principal.equals(request.getClientInfo().getUser()))
183-
&& (!request.getClientInfo().getRoles()
184-
.contains(principal))
185-
&& (!request.getClientInfo().getPrincipals()
186-
.contains(principal))) {
181+
&& (!request.getClientInfo().getRoles().contains(principal))
182+
&& (!request.getClientInfo().getPrincipals().contains(principal))) {
187183
request.getClientInfo().getPrincipals().add(principal);
188184
}
189185
/*
@@ -192,11 +188,8 @@ public int verify(Request request, Response response) {
192188
* principal's name.
193189
*/
194190
if ((request.getClientInfo().getUser() == null)
195-
&& (this.userPrincipalClassName != null)
196-
&& (principal.getClass().getName()
197-
.equals(this.userPrincipalClassName))) {
198-
request.getClientInfo().setUser(
199-
new User(principal.getName()));
191+
&& (principal.getClass().getName().equals(this.userPrincipalClassName))) {
192+
request.getClientInfo().setUser(new User(principal.getName()));
200193
}
201194
}
202195
} catch (LoginException le) {

modules/org.restlet.ext.jackson/src/org/restlet/ext/jackson/JacksonRepresentation.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class JacksonRepresentation<T> extends OutputRepresentation {
6767
* Default value provided by system property
6868
* "org.restlet.ext.xml.expandingEntityRefs", false by default.
6969
*/
70-
public static boolean XML_EXPANDING_ENTITY_REFS = Boolean
70+
public final static boolean XML_EXPANDING_ENTITY_REFS = Boolean
7171
.getBoolean("org.restlet.ext.xml.expandingEntityRefs");
7272

7373
// [ifndef android] member
@@ -76,7 +76,7 @@ public class JacksonRepresentation<T> extends OutputRepresentation {
7676
* Default value provided by system property
7777
* "org.restlet.ext.xml.validatingDtd", false by default.
7878
*/
79-
public static boolean XML_VALIDATING_DTD = Boolean
79+
public final static boolean XML_VALIDATING_DTD = Boolean
8080
.getBoolean("org.restlet.ext.xml.validatingDtd");
8181

8282
/** The modifiable Jackson CSV schema. */

0 commit comments

Comments
 (0)