Skip to content

Commit

Permalink
Fixed potential NPE and refactored some code.
Browse files Browse the repository at this point in the history
  • Loading branch information
thboileau committed May 15, 2016
1 parent dc6f513 commit a72a924
Show file tree
Hide file tree
Showing 72 changed files with 1,595 additions and 2,176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static void process(String[] args) throws TranslationException {
Engine.register();
String ulogin = null;
String upwd = null;
String serviceUrl = null;
String serviceUrl = "https://apispark.restlet.com/";
String defSource = null;
String compName = null;
String language = null;
Expand Down Expand Up @@ -251,9 +251,6 @@ public static void process(String[] args) throws TranslationException {
+ " is not currently supported. ");
}

if (StringUtils.isNullOrEmpty(serviceUrl)) {
serviceUrl = "https://apispark.restlet.com/";
}
if (!serviceUrl.endsWith("/")) {
serviceUrl += "/";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void run() {
*/
private long getRetryTime(int attemptNumber) {
long newTime = RETRY_AFTER
* ((int) Math.pow(2.0, attemptNumber - 1));
* ((int) Math.pow(2.0d, attemptNumber - 1));
return Math.min(newTime, MAX_TIME);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public int verify(Request request, Response response) {
result = RESULT_MISSING;
} else {
String nonce = cr.getServerNonce();
String uri = (cr.getDigestRef() == null) ? null : cr.getDigestRef()
.toString();
String uri = (cr.getDigestRef() == null) ? null : cr.getDigestRef().toString();
String qop = cr.getQuality();
int nc = cr.getServerNounceCount();
String cnonce = cr.getClientNonce();
Expand Down
117 changes: 53 additions & 64 deletions modules/org.restlet.ext.gwt/src/org/restlet/ext/gwt/GwtConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

package org.restlet.ext.gwt;

import static org.restlet.data.MediaType.APPLICATION_JAVA_OBJECT_GWT;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;
Expand All @@ -47,8 +49,7 @@
public class GwtConverter extends ConverterHelper {

/** GWT variant. */
private static final VariantInfo VARIANT_GWT = new VariantInfo(
MediaType.APPLICATION_JAVA_OBJECT_GWT);
private static final VariantInfo VARIANT_GWT = new VariantInfo(APPLICATION_JAVA_OBJECT_GWT);

@Override
public List<Class<?>> getObjectClasses(Variant source) {
Expand Down Expand Up @@ -77,92 +78,81 @@ public List<VariantInfo> getVariants(Class<?> source) {

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

if (source instanceof Serializable || source instanceof IsSerializable) {
if (target == null) {
result = 0.5F;
} else if (MediaType.APPLICATION_JAVA_OBJECT_GWT.equals(target
.getMediaType())) {
result = 1.0F;
} else if (MediaType.APPLICATION_JAVA_OBJECT_GWT
.isCompatible(target.getMediaType())) {
result = 0.6F;
} else {
result = 0.5F;
return 0.5F;
}
if (APPLICATION_JAVA_OBJECT_GWT.equals(target.getMediaType())) {
return 1.0F;
}
if (APPLICATION_JAVA_OBJECT_GWT.isCompatible(target.getMediaType())) {
return 0.6F;
}
return 0.5F;
}

return result;
return -1.0F;
}

@Override
public <T> float score(Representation source, Class<T> target,
Resource resource) {
float result = -1.0F;

public <T> float score(Representation source, Class<T> target, Resource resource) {
if (source instanceof ObjectRepresentation<?>) {
result = 1.0F;
} else if ((target != null)
&& ObjectRepresentation.class.isAssignableFrom(target)) {
result = 1.0F;
} else if ((target != null)
&& (Serializable.class.isAssignableFrom(target) || IsSerializable.class
.isAssignableFrom(target))) {
if (MediaType.APPLICATION_JAVA_OBJECT_GWT.equals(source
.getMediaType())) {
result = 1.0F;
} else if (MediaType.APPLICATION_JAVA_OBJECT_GWT
.isCompatible(source.getMediaType())) {
result = 0.6F;
return 1.0F;
}

if (target != null) {
if (ObjectRepresentation.class.isAssignableFrom(target)) {
return 1.0F;
}
if (Serializable.class.isAssignableFrom(target)
|| IsSerializable.class.isAssignableFrom(target)) {
if (APPLICATION_JAVA_OBJECT_GWT.equals(source.getMediaType())) {
return 1.0F;
}
if (APPLICATION_JAVA_OBJECT_GWT.isCompatible(source.getMediaType())) {
return 0.6F;
}
}
}

return result;
return -1.0F;
}

@SuppressWarnings("unchecked")
@Override
public <T> T toObject(Representation source, Class<T> target,
Resource resource) throws IOException {
ObjectRepresentation<?> gwtSource = null;
if (source instanceof ObjectRepresentation<?>) {
gwtSource = (ObjectRepresentation<?>) source;
} else {
gwtSource = new ObjectRepresentation<T>(source.getText(), target);
}
public <T> T toObject(Representation source, Class<T> target, Resource resource) throws IOException {
ObjectRepresentation<?> gwtSource = (source instanceof ObjectRepresentation<?>) ?
(ObjectRepresentation<?>) source :
new ObjectRepresentation<T>(source.getText(), target);

T result = null;
if (gwtSource != null) {
if (target == null) {
result = (T) gwtSource.getObject();
} else if (ObjectRepresentation.class.isAssignableFrom(target)) {
result = (T) gwtSource;
} else if (Serializable.class.isAssignableFrom(target)
|| IsSerializable.class.isAssignableFrom(target)) {
result = (T) gwtSource.getObject();
}
if (target == null) {
return (T) gwtSource.getObject();
}
if (ObjectRepresentation.class.isAssignableFrom(target)) {
return (T) gwtSource;
}
if (Serializable.class.isAssignableFrom(target)
|| IsSerializable.class.isAssignableFrom(target)) {
return (T) gwtSource.getObject();
}

return result;
return null;
}

@Override
public Representation toRepresentation(Object source, Variant target,
Resource resource) {
Representation result = null;

public Representation toRepresentation(Object source, Variant target, Resource resource) {
if (source instanceof Serializable) {
result = new ObjectRepresentation<Serializable>(
(Serializable) source);
} else if (source instanceof IsSerializable) {
result = new ObjectRepresentation<IsSerializable>(
(IsSerializable) source);
} else if (source instanceof Representation) {
result = (Representation) source;
return new ObjectRepresentation<Serializable>((Serializable) source);
}
if (source instanceof IsSerializable) {
return new ObjectRepresentation<IsSerializable>((IsSerializable) source);
}
if (source instanceof Representation) {
return (Representation) source;
}

return result;
return null;
}

@Override
Expand All @@ -171,8 +161,7 @@ public <T> void updatePreferences(List<Preference<MediaType>> preferences,
if (Serializable.class.isAssignableFrom(entity)
|| IsSerializable.class.isAssignableFrom(entity)
|| ObjectRepresentation.class.isAssignableFrom(entity)) {
updatePreferences(preferences,
MediaType.APPLICATION_JAVA_OBJECT_GWT, 1.0F);
updatePreferences(preferences, APPLICATION_JAVA_OBJECT_GWT, 1.0F);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@
* Verifier that leverages the JAAS pluggable authentication mechanism.
*
* @author Jerome Louvel
* @see <a
* href="http://download.oracle.com/javase/1.5.0/docs/guide/security/jaas/tutorials/index.html">JAAS
* @see <a href="http://download.oracle.com/javase/1.5.0/docs/guide/security/jaas/tutorials/index.html">JAAS
* Tutorials</a>
* @see <a
* href="http://download.oracle.com/javase/1.5.0/docs/guide/security/jaas/JAASRefGuide.html">JAAS
* Reference Guide</a>
* @see <a href="http://download.oracle.com/javase/1.5.0/docs/guide/security/jaas/JAASRefGuide.html">JAAS Reference
* Guide</a>
*/
public class JaasVerifier implements Verifier {

Expand Down Expand Up @@ -131,8 +129,8 @@ public void setName(String contextName) {
/**
* Sets the user principal class name. If a {@link User} is not associated
* with the {@link Request}'s {@link ClientInfo} and if one of the
* principals returned after the JAAS login is of this type, a new
* {@link User} will be associated with the {@link ClientInfo} using its
* principals returned after the JAAS login is of this type, a new {@link User} will be associated with the
* {@link ClientInfo} using its
* name.
*
* @param userPrincipalClassName
Expand Down Expand Up @@ -180,10 +178,8 @@ public int verify(Request request, Response response) {
*/
for (Principal principal : subject.getPrincipals()) {
if ((!principal.equals(request.getClientInfo().getUser()))
&& (!request.getClientInfo().getRoles()
.contains(principal))
&& (!request.getClientInfo().getPrincipals()
.contains(principal))) {
&& (!request.getClientInfo().getRoles().contains(principal))
&& (!request.getClientInfo().getPrincipals().contains(principal))) {
request.getClientInfo().getPrincipals().add(principal);
}
/*
Expand All @@ -192,11 +188,8 @@ public int verify(Request request, Response response) {
* principal's name.
*/
if ((request.getClientInfo().getUser() == null)
&& (this.userPrincipalClassName != null)
&& (principal.getClass().getName()
.equals(this.userPrincipalClassName))) {
request.getClientInfo().setUser(
new User(principal.getName()));
&& (principal.getClass().getName().equals(this.userPrincipalClassName))) {
request.getClientInfo().setUser(new User(principal.getName()));
}
}
} catch (LoginException le) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class JacksonRepresentation<T> extends OutputRepresentation {
* Default value provided by system property
* "org.restlet.ext.xml.expandingEntityRefs", false by default.
*/
public static boolean XML_EXPANDING_ENTITY_REFS = Boolean
public final static boolean XML_EXPANDING_ENTITY_REFS = Boolean
.getBoolean("org.restlet.ext.xml.expandingEntityRefs");

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

/** The modifiable Jackson CSV schema. */
Expand Down
Loading

0 comments on commit a72a924

Please sign in to comment.