Slide 1

Slide 1 text

ErrorProne Makoto Yamazaki #RealmWorldTour17

Slide 2

Slide 2 text

Now we are introducing ErrorProne http://errorprone.info/ https://github.com/google/error-prone [email protected]

Slide 3

Slide 3 text

ErrorProneͱ͸ • Ϗϧυͷࡍʹࣗಈతʹ࣮ߦ͞Ε • ίϯύΠϥʔ͕ߦ͏νΣοΫҎ্ͷޡΓݕ஌Λߦ͍ • ݕ஌ͨ͠ޡΓʹରͯ͠मਖ਼ͷఏҊΛߦ͏ [email protected] ͱ͍͏͜ͱΛͯ͘͠ΕΔπʔϧ

Slide 4

Slide 4 text

ಋೖͷ͖͔͚ͬ • Realm͕ੜ੒͢Δίʔυʹ͍ͭͯ ErrorProne Ͱܯࠂग़Δ͔ΒͳΜͱ͔͠ ͯ΄͍͠ͱ͍͏issue্͕͕Δ realm/realm-java#4329 • ੜ੒͞ΕΔίʔυΛमਖ਼͢ΔPRΛ࡞੒ realm/realm-java#4338 • ࠓޙͷमਖ਼Ͱ·ͨܯࠂ͕ग़ΔΑ͏ʹͳΔͱ͍͚ͳ͍ͷͰɺςετʹ଍͠ ͍ͨΑͶͱ͍͏࿩ʹͳΔ • Realm Javaຊମ΍ςετίʔυͰ΋ίʔυੜ੒͍ͯ͠ΔͷͰɺ͔ͤͬ͘ ͔ͩΒRealm JavaࣗମʹErrorProneΛద༻ͨ͠ realm/realm-java#4342 [email protected]

Slide 5

Slide 5 text

ޡΓݕग़ͷྫ(ެࣜαΠτΑΓ) [email protected] public class ShortSet {
 public static void main (String[] args) {
 Set s = new HashSet<>();
 for (short i = 0; i < 100; i++) {
 s.add(i);
 s.remove(i - 1);
 }
 System.out.println(s.size());
 }
 } $ bazel build :hello ERROR: example/myproject/BUILD:29:1: Java compilation in rule '//example/myproject:hello' ShortSet.java:6: error: [CollectionIncompatibleType] Argument 'i - 1' should not be passed to this method; its type int is not compatible with its collection's type argument Short s.remove(i - 1); ^ (see http://errorprone.info/bugpattern/CollectionIncompatibleType) 1 error

Slide 6

Slide 6 text

ಋೖํ๏ [email protected] // in build.gradle buildscript { repositories { maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.9' } } // in app/build.gradle apply plugin: 'net.ltgt.errorprone' https://github.com/tbroyer/gradle-errorprone-plugin

Slide 7

Slide 7 text

• ςετέʔε΁ͷ @Test Ξϊςʔγϣϯ෇༩๨Ε • byteྻͱจࣈྻͷม׵ͷࡍͷΤϯίʔσΟϯάࢦఆ࿙Ε • ແବͳϓϦϛςΟϒϥούʔΠϯελϯεੜ੒ • @OverrideΞϊςʔγϣϯ෇༩๨Ε • switch-case Ͱͷbreak࿙Ε • ྫ֎Λظ଴͢ΔςετέʔεͰग़ͳ͔ͬͨ৔߹ͷfail()ݺͼग़͠࿙Ε • Enumʹఆٛͨ͠ϑΟʔϧυ͕non final • shortͷఆ਺Ͱͷਫ਼౓ෆ଍ [email protected] ࣮ࡍʹݕग़͞ΕͨޡΓͷྫ

Slide 8

Slide 8 text

@Test Ξϊςʔγϣϯ෇༩๨Ε [email protected] realm-java/realm/realm-library/src/androidTest/java/io/realm/DynamicRealmObjectTests.java: 1244: エラー: [JUnit4TestNotRun] Test method will not be run; please add @Test annotation public void testExceptionMessage() { ^ (see http://errorprone.info/bugpattern/JUnit4TestNotRun) Did you mean '@Test'?

Slide 9

Slide 9 text

ΤϯίʔσΟϯάࢦఆ࿙Ε [email protected] realm-library/src/androidTest/java/io/realm/TestHelper.java:129: 警告: [DefaultCharset] Implicit use of the platform default charset, which can result in e.g. non-ASCII characters being silently replaced with '?' in many environments br = new BufferedReader(new InputStreamReader(in)); ^ (see http://errorprone.info/bugpattern/DefaultCharset) Did you mean 'br = new BufferedReader(new InputStreamReader(in, UTF_8));' or 'br = new BufferedReader(new InputStreamReader(in, Charset.defaultCharset()));'?

Slide 10

Slide 10 text

ແବͳΠϯελϯεੜ੒ [email protected] realm-library/src/androidTest/java/io/realm/TestHelper.java:407: 警告: [BoxedPrimitiveConstructor] valueOf or autoboxing provides better time and space performance obj.setId(new Short(idValue)); ^ (see http://errorprone.info/bugpattern/BoxedPrimitiveConstructor) Did you mean 'obj.setId(Short.valueOf(idValue));'?

Slide 11

Slide 11 text

@OverrideΞϊςʔγϣϯ࿙Ε [email protected] realm-library/src/main/java/io/realm/RealmCollection.java:175: 警告: [MissingOverride] contains implements method in Collection; expected @Override boolean contains(Object object); ^ (see http://errorprone.info/bugpattern/MissingOverride) Did you mean '@Override boolean contains(Object object);'?

Slide 12

Slide 12 text

switch-caseͰͷbreak࿙Ε [email protected] realm-library/src/androidTest/java/io/realm/ManagedRealmCollectionTests.java:773: エラー: [FallThrough] Switch case may fall through; add a `// fall through` comment if it was deliberate case ADD_ALL_OBJECTS: collection.addAll(Collections.singletonList(new AllJavaTypes())); break; ^ (see http://errorprone.info/bugpattern/FallThrough)

Slide 13

Slide 13 text

fail()ͷݺͼग़͠࿙Ε [email protected] realm-library/src/androidTest/java/io/realm/RealmCacheTests.java:108: 警告: [MissingFail] Not calling fail() when expecting an exception masks bugs Realm.getInstance(configB); // Tries to open with key 2. ^ (see http://errorprone.info/bugpattern/MissingFail) Did you mean 'Realm.getInstance(configB);'?

Slide 14

Slide 14 text

Enum಺ͷϑΟʔϧυ͕non final [email protected] realm-library/src/androidTest/java/io/realm/RealmObjectSchemaTests.java:114: 警告: [ImmutableEnumChecker] enums should be immutable, and cannot have non-final fields Class> clazz; ^ (see http://errorprone.info/bugpattern/ImmutableEnumChecker) Did you mean 'final Class> clazz;'?

Slide 15

Slide 15 text

shortͷఆ਺Ͱͷਫ਼౓ෆ଍ [email protected] realm-library/src/androidTest/java/io/realm/RealmQueryTests.java:511: 警告: [FloatingPointLiteralPrecision] Floating point literal loses precision .greaterThanOrEqualTo(AllTypes.FIELD_FLOAT, 50.234567f).findAll(); ^ (see http://errorprone.info/bugpattern/FloatingPointLiteralPrecision) Did you mean '.greaterThanOrEqualTo(AllTypes.FIELD_FLOAT, 50.234566f).findAll();'?