Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Realm World Tour - ErrorProne in Realm Java

March 26, 2017

Realm World Tour - ErrorProne in Realm Java


March 26, 2017

More Decks by zaki50

Other Decks in Technology


  1. ErrorProne Makoto Yamazaki #RealmWorldTour17

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

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

  4. ಋೖͷ͖͔͚ͬ • Realm͕ੜ੒͢Δίʔυʹ͍ͭͯ ErrorProne Ͱܯࠂग़Δ͔ΒͳΜͱ͔͠ ͯ΄͍͠ͱ͍͏issue্͕͕Δ realm/realm-java#4329 • ੜ੒͞ΕΔίʔυΛमਖ਼͢ΔPRΛ࡞੒ realm/realm-java#4338

    • ࠓޙͷमਖ਼Ͱ·ͨܯࠂ͕ग़ΔΑ͏ʹͳΔͱ͍͚ͳ͍ͷͰɺςετʹ଍͠ ͍ͨΑͶͱ͍͏࿩ʹͳΔ • Realm Javaຊମ΍ςετίʔυͰ΋ίʔυੜ੒͍ͯ͠ΔͷͰɺ͔ͤͬ͘ ͔ͩΒRealm JavaࣗମʹErrorProneΛద༻ͨ͠ realm/realm-java#4342 [email protected]
  5. ޡΓݕग़ͷྫ(ެࣜαΠτΑΓ) [email protected] public class ShortSet {
 public static void main

    (String[] args) {
 Set<Short> s = new HashSet<>();
 for (short i = 0; i < 100; i++) {
 s.remove(i - 1);
 } $ 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
  6. ಋೖํ๏ [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
  7. • ςετέʔε΁ͷ @Test Ξϊςʔγϣϯ෇༩๨Ε • byteྻͱจࣈྻͷม׵ͷࡍͷΤϯίʔσΟϯάࢦఆ࿙Ε • ແବͳϓϦϛςΟϒϥούʔΠϯελϯεੜ੒ • @OverrideΞϊςʔγϣϯ෇༩๨Ε

    • switch-case Ͱͷbreak࿙Ε • ྫ֎Λظ଴͢ΔςετέʔεͰग़ͳ͔ͬͨ৔߹ͷfail()ݺͼग़͠࿙Ε • Enumʹఆٛͨ͠ϑΟʔϧυ͕non final • shortͷఆ਺Ͱͷਫ਼౓ෆ଍ [email protected] ࣮ࡍʹݕग़͞ΕͨޡΓͷྫ
  8. @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'?
  9. ΤϯίʔσΟϯάࢦఆ࿙Ε [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()));'?
  10. ແବͳΠϯελϯεੜ੒ [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));'?
  11. @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);'?
  12. 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)
  13. 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);'?
  14. 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;'?
  15. 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();'?