Skip to content

Add Checker framework, enable format string and interning checkers #1239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
968 changes: 499 additions & 469 deletions pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public void process() throws IOException {
while (true) {
if (savedImages && userChoice != -1) {
if (userChoice == 1) {
UtilImageIO.savePPM(savedRgb, String.format(directory + "rgb%07d.ppm", frameNumber), buffer);
UtilOpenKinect.saveDepth(savedDepth, String.format(directory + "depth%07d.depth", frameNumber), buffer);
UtilImageIO.savePPM(savedRgb, String.format("%srgb%07d.ppm", directory, frameNumber), buffer);
UtilOpenKinect.saveDepth(savedDepth, String.format("%sdepth%07d.depth", directory, frameNumber), buffer);
frameNumber++;
text = "Image Saved!";
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/myrobotlab/cmdline/CmdLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;

public class CmdLine extends HashMap<String, CcmdParam> {

Expand Down Expand Up @@ -155,7 +156,7 @@ public int splitLine(String[] args) {
CcmdParam cmd = new CcmdParam();

// only add non-empty args
if (arg != "") {
if (!Objects.equals(arg, "")) {
cmd.m_strings.add(arg);
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/myrobotlab/codec/CodecUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.internal.LinkedTreeMap;
import org.checkerframework.checker.interning.qual.FindDistinct;
import org.checkerframework.checker.interning.qual.Interned;
import org.myrobotlab.codec.json.GsonPolymorphicTypeAdapterFactory;
import org.myrobotlab.codec.json.JacksonPolymorphicModule;
import org.myrobotlab.codec.json.JsonDeserializationException;
Expand Down Expand Up @@ -1218,9 +1220,10 @@ public static void setField(Object o, String field, Object value) {
// TODO - handle all types :P
Field f = o.getClass().getDeclaredField(field);
f.setAccessible(true);
f.set(o, value);
// Checker doesn't like using non-interned values for Field.set() for some reason
f.set(o, (@Interned Object) value);
} catch (Exception e) {
/** don't care - if its not there don't set it */
/* don't care - if its not there don't set it */
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/myrobotlab/codec/serial/Codec.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import org.checkerframework.checker.formatter.qual.FormatMethod;
import org.myrobotlab.framework.interfaces.LoggingSink;
import org.myrobotlab.logging.LoggerFactory;
import org.slf4j.Logger;
Expand Down Expand Up @@ -103,6 +104,7 @@ final public String decode(int newByte) {

abstract public int[] encode(String source);

@FormatMethod
public void error(String format, Object... args) {
if (sink != null) {
sink.error(format, args);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/myrobotlab/framework/CmdOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Arrays;
import java.util.List;

import org.checkerframework.checker.interning.qual.Interned;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

Expand Down Expand Up @@ -113,7 +114,7 @@ public CmdOptions() {
public CmdOptions(CmdOptions other) throws IllegalArgumentException, IllegalAccessException {
Field[] fields = this.getClass().getDeclaredFields();
for (Field field : fields) {
field.set(this, field.get(other));
field.set(this, (@Interned Object) field.get(other));
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/myrobotlab/framework/MrlException.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.myrobotlab.framework;

import org.checkerframework.checker.formatter.qual.FormatMethod;

public class MrlException extends Exception {

private static final long serialVersionUID = 1L;

@FormatMethod
public MrlException(String format, Object... params) {
super(String.format(format, params));
}
Expand Down
Loading