2017-03-23

Java: Silence Eclipse's Null Type Safety Warnings Where It Shouldn't

So you just enabled "Null analysis" in Eclipse, and set a reasonable NonNull annotation to confom (ie. javax.validation.constraints.NotNull), also started annotating the relevant methods with it.

But.
When using the new Java 8 Streams API, Eclipse warns inside the functions you toss in, even if you've filtered out the null ones.

I'll give you an example:
1
2
3
4
// ...inside the Foo class...
public Foo(@NotNull final Bar bar) {
        this.bar = Objects.requireNonNull(bar, "Shame...");
}
1
2
3
4
5
6
7
8
9
// ...inside somewhere completely unrelated...
public Optional<Foo> getFoobarizedBarBaz() {
        return Optional.ofNullable(
                fooService.getBar()
                        .stream()
                                .filter(Objects::nonNull) // yeah, so no nulls, plz
                                .map(bar -> new Foo(bar /* Oh no, yellow underline*/, someLocalValue)
                                .findAny());
}

But oh, the "bar" is underlined, stating "Null type safety: The expression of type 'Bar' needs unchecked conversion to conform to '@NotNull Bar'"...

If only there were a way to resolve that...wait, there is! We can set the type of the formal parameters inside the lambda expression!
1
2
3
4
5
6
7
8
9
// ...inside somewhere completely unrelated...
public Optional<Foo> getFoobarizedBarBaz() {
        return Optional.ofNullable(
                fooService.getBar()
                        .stream()
                                .filter(Objects::nonNull)
                                .map((@NotNull Bar bar) -> new Foo(bar, someLocalValue)
                                .findAny());
}

Formal parameters. PARAMETERS.
@NotNull's @Target annotation includes PARAMETER.
Even it's comment states: "Formal parameter declaration".

Win.

2017-03-17

hosts: Blocking noxious sites effectively

Years ago I found this cool website: http://someonewhocares.org/hosts/

It blocks a lot of sites you don't normally want to visit :)

Also, I have a Hungary-specific compilation of anti-science / russian propaganda / simply dumb sites (and a few USA-specific ones) you don't want to stumble upon:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#<hu-russian-propaganda>
127.0.0.1 888.hu
127.0.0.1 adatlistazo.hu
127.0.0.1 aktiv-blog.net
127.0.0.1 aktivblog.net
127.0.0.1 atomenergiainfo.hu # powered by rosatom :)
127.0.0.1 balrad.com
127.0.0.1 bejegyzes.com
127.0.0.1 civilkontroll.com
127.0.0.1 debmedia.hu
127.0.0.1 elkepeszto.net
127.0.0.1 hidfo.net
127.0.0.1 hidfo.ru
127.0.0.1 hir.club
127.0.0.1 hirado.top
127.0.0.1 hirarena.eu
127.0.0.1 hircentrum.top
127.0.0.1 hirek.in
127.0.0.1 hirek.top
127.0.0.1 hirekonline.net
127.0.0.1 hirexpressz.top
127.0.0.1 hirhatar.hu
127.0.0.1 hirkert.info
127.0.0.1 hirkozpont.eu
127.0.0.1 hirlistazo.com
127.0.0.1 hirma.info
127.0.0.1 hirmagazin.eu
127.0.0.1 hironline.club
127.0.0.1 hirportal.info
127.0.0.1 hirtop.in
127.0.0.1 hirtrafik.top
127.0.0.1 hirvilag.eu
127.0.0.1 hungarian.ruvr.ru
127.0.0.1 hunhir.hu
127.0.0.1 hunhir.info
127.0.0.1 hunhonlap.hu
127.0.0.1 hunsor.se
127.0.0.1 huntv.info
127.0.0.1 impulzus.net
127.0.0.1 internetfigyelo.wordpress.com
127.0.0.1 jovonk.info
127.0.0.1 kho.jobbikhosting.com
127.0.0.1 kitartas.net
127.0.0.1 kulfoldiapro.com
127.0.0.1 kuruc.info
127.0.0.1 legfrissebb.info
127.0.0.1 lovasistvan.hu
127.0.0.1 ma.hu
127.0.0.1 magyarifjak.org
127.0.0.1 magyarmegmaradasert.hu
127.0.0.1 magyarno.com
127.0.0.1 magyartudat.com
127.0.0.1 maivalosag.com
127.0.0.1 meteon.org
127.0.0.1 mindenegyben-blog.net
127.0.0.1 mindenegyben.net
127.0.0.1 mindenegybenblog.com
127.0.0.1 mokazona.eu
127.0.0.1 napihirozon.eu
127.0.0.1 napimigrans.com
127.0.0.1 nemadomahazamat.hu
127.0.0.1 nemzeti.net
127.0.0.1 nemzetiarcvonal.net
127.0.0.1 nemzetibulvar.hu
127.0.0.1 nemzetihirhalo.hu
127.0.0.1 netbulvar.com
127.0.0.1 netbulvar.eu
127.0.0.1 netceleb.eu
127.0.0.1 netceleb.hu
127.0.0.1 nethir.com
127.0.0.1 orientalista.hu
127.0.0.1 oroszhirek.hu
127.0.0.1 paxhungarica.org
127.0.0.1 rapidpress.info
127.0.0.1 realzoldek.hu
127.0.0.1 simsim.eu
127.0.0.1 sokkaljobb.hu
127.0.0.1 szabadriport.wordpress.com
127.0.0.1 szentkoronaradio.hu
127.0.0.1 thenews.hu
127.0.0.1 titkolthirek.hu
127.0.0.1 totalcar.top
127.0.0.1 tvhir.com
127.0.0.1 videohirek.com
127.0.0.1 vilaghalo.info
127.0.0.1 vilagom.hu
127.0.0.1 adatlistazo.hu
127.0.0.1 hidfo.net
127.0.0.1 xcore.in
#</hu-russian-propaganda>
  
#<hu-conteo-sites>
## These are Hungarian sites spreading bullshit (typical antivaxxer, anti-science, and/or fake news sites).
127.0.0.1 2perc.info
127.0.0.1 aktiv-hir.net
127.0.0.1 aktivhir.net
127.0.0.1 atomenergiainfo.hu
127.0.0.1 avilagtitkai.com
127.0.0.1 best-hir.com
127.0.0.1 bizony.eu
127.0.0.1 csucshatas.eu
127.0.0.1 csumida.com
127.0.0.1 dekutya.com
127.0.0.1 egeszsegmindenkinek.hu
127.0.0.1 epic-info.com
127.0.0.1 ez-zsir.net
127.0.0.1 ezt-figyeld.com
127.0.0.1 filmtar.in
127.0.0.1 frenetikus.com
127.0.0.1 hirado-online.net
127.0.0.1 hirexpressz.top
127.0.0.1 hirkert.info
127.0.0.1 hirnap.info
127.0.0.1 hirtop.in
127.0.0.1 husospizza.com
127.0.0.1 impulzus.net
127.0.0.1 index-video.com
127.0.0.1 magyarkozosseg.net
127.0.0.1 mindenegyben-blog.net
127.0.0.1 mindenegybenblog.hu
127.0.0.1 mindenegyhelyen.info
127.0.0.1 napi-hir.net
127.0.0.1 napiszarka.com
127.0.0.1 nemkutya.com
127.0.0.1 netextra.hu
127.0.0.1 nyaralok.net
127.0.0.1 origo-hir.net
127.0.0.1 origo-hirek.net
127.0.0.1 origo-online.info
127.0.0.1 origo-online.net
127.0.0.1 origoblog.net
127.0.0.1 origohir.net
127.0.0.1 origoonline.net
127.0.0.1 szupcsi.eu
127.0.0.1 tudnodkel.blogspot.com
127.0.0.1 tudnodkell.blogspot.com
127.0.0.1 tutihirek.com
127.0.0.1 vakarek.info
127.0.0.1 valoshirek.top
127.0.0.1 vattacukor.net
127.0.0.1 video-perc.net
127.0.0.1 hirnap.info
127.0.0.1 video-perc.net
#</hu-conteo-sites>
  
#<us-fake-news-sites>
127.0.0.1 100percentfedup.com
127.0.0.1 21stcenturywire.com
127.0.0.1 70news.wordpress.com
127.0.0.1 abcnews.com.co
127.0.0.1 activistpost.com
127.0.0.1 addictinginfo.org
127.0.0.1 americannewsx.com
127.0.0.1 americannews.com
127.0.0.1 anonnews.co
127.0.0.1 associatedmediacoverage.com
127.0.0.1 thebostontribune.com
127.0.0.1 beforeitsnews.com
127.0.0.1 beingliberal.org
127.0.0.1 bigamericannews.com
127.0.0.1 bigpzone.com
127.0.0.1 bipartisanreport.com
127.0.0.1 bizpacreview.com
127.0.0.1 bluenationreview.com
127.0.0.1 breitbart.com
127.0.0.1 cap-news.com
127.0.0.1 christwire.org
127.0.0.1 chronicle.su
127.0.0.1 civictribune.com
127.0.0.1 clickhole.com
127.0.0.1 coasttocoastam.com
127.0.0.1 collective-evolution.com
127.0.0.1 consciouslifenews.com
127.0.0.1 conservativeoutfitters.com
127.0.0.1 wideawakeamerica.com
127.0.0.1 countdowntozerotime.com
127.0.0.1 counterpsyops.com
127.0.0.1 creambmp.com
127.0.0.1 crooksandliars.com
127.0.0.1 dcclothesline.com
127.0.0.1 dcgazette.com
127.0.0.1 dailywire.com
127.0.0.1 dailybuzzlive.com
127.0.0.1 dailycurrant.com
127.0.0.1 derfmagazine.com
127.0.0.1 disclose.tv
127.0.0.1 drudgereport.com.co
127.0.0.1 duffleblog.com
127.0.0.1 duhprogressive.com
127.0.0.1 embols.com
127.0.0.1 empireherald.com
127.0.0.1 empirenews.net
127.0.0.1 empirenews.com
127.0.0.1 endingthefed.com
127.0.0.1 enduringvision.com
127.0.0.1 fprnradio.com
127.0.0.1 geoengineeringwatch.org
127.0.0.1 globalresearch.ca
127.0.0.1 govtslaves.info
127.0.0.1 gulagbound.com
127.0.0.1 hangthebankers.com
127.0.0.1 humansarefree.com
127.0.0.1 huzlers.com
127.0.0.1 ijr.com
127.0.0.1 ifyouonlynews.com
127.0.0.1 indecisionforever.com
127.0.0.1 infowars.com
127.0.0.1 inquisitr.com
127.0.0.1 intellihub.com
127.0.0.1 jonesreport.com
127.0.0.1 lewrockwell.com
127.0.0.1 liberalamerica.org
127.0.0.1 libertymovementradio.com
127.0.0.1 libertytalk.fm
127.0.0.1 libertyunyielding.com
127.0.0.1 libertyvideos.org
127.0.0.1 msnbc.com.co
127.0.0.1 msnbc.website
127.0.0.1 mediamass.net
127.0.0.1 megynkelly.us
127.0.0.1 ncscooper.com
127.0.0.1 nahadaily.com
127.0.0.1 nationalreport.net
127.0.0.1 naturalnews.com
127.0.0.1 newcenturytimes.com
127.0.0.1 newsexaminer.com
127.0.0.1 news-hound.com
127.0.0.1 newsbiscuit.com
127.0.0.1 newsbuzzdaily.com
127.0.0.1 newsmutiny.com
127.0.0.1 newswire-24.com
127.0.0.1 newslo.com
127.0.0.1 newswatch28.com
127.0.0.1 newswatch33.com
127.0.0.1 nodisinfo.com
127.0.0.1 now8news.com
127.0.0.1 nowtheendbegins.com
127.0.0.1 occupydemocrats.com
127.0.0.1 pakalertpress.com
127.0.0.1 politicalblindspot.com
127.0.0.1 politicalears.com
127.0.0.1 politicususa.com
127.0.0.1 prisonplanet.com
127.0.0.1 prisonplanet.tv
127.0.0.1 private-eye.co.uk
127.0.0.1 projectveritas.com
127.0.0.1 react365.com
127.0.0.1 realfarmacy.com
127.0.0.1 realnewsrightnow.com
127.0.0.1 redstate.com
127.0.0.1 redflagnews.com
127.0.0.1 reductress.com
127.0.0.1 rilenews.com
127.0.0.1 satiratribune.com
127.0.0.1 sprotspickle.com
127.0.0.1 theblaze.com
127.0.0.1 thefreethoughtproject.com
127.0.0.1 other98.com
127.0.0.1 thereporter.com
127.0.0.1 thedailysheeple.com
127.0.0.1 thenewsnerd.com
127.0.0.1 therundownlive.com
127.0.0.1 theuspatriot.com
127.0.0.1 truthfrequencyradio.com
127.0.0.1 twitchy.com
127.0.0.1 usuncut.com
127.0.0.1 usasupreme.com
127.0.0.1 unconfirmedsources.com
127.0.0.1 veteranstoday.com
127.0.0.1 wakingupwisconsin.com
127.0.0.1 wakingtimes.com
127.0.0.1 wideawakeamerica.com
127.0.0.1 winningdemocrats.com
127.0.0.1 witscience.org
127.0.0.1 wnd.com
127.0.0.1 worldnewsdailyreport.com
127.0.0.1 worldtruth.tv
127.0.0.1 zerohedge.com
#</us-fake-news-sites>

Do not forget to regularly update :)