Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

Java

情報システムにおける「排他処理」のバリエーション

一言で「排他処理」と言っても、Javaで実装したWebシステムで「排他」というキーワードに関連する処理を考えただけでもこれだけある。初学者はこれらがごっちゃになることも多いんじゃないかと思うのだけれど、こういう切り口でノウハウをまとめた書籍とかっ…

OpenClover 4.5.0リリース

Javaのコードカバレッジ取得ツールOpenCloverの新バージョン 4.5.0が2023年10月4日にリリースされました。 OpenClover - Java, Groovy and AspectJ code coverage tool OpenCloverのいいところは以下の記事にも書いたとおり、ソースコードレベルのC1カバレッ…

System.currentTimeMillis()のOS・JavaVMごとの精度

動機 JavaのSystem.currentTimeMillis()の説明*1には以下のように書いてあるけど本当? System.currentTimeMillis()とSystem.nanoTime()で試してみた。 たとえば、多くのオペレーティング・システムでは、時間を10ミリ秒の単位で計測します。 方法 以下のプ…

JavaVMがOOM Killerでkillされた際にヒープダンプは出力されない

JavaVM内でOutOfMemoryErrorが発生した場合は、当然オプションに従ってヒープダンプ(java_pid*.hprof)が出力される。 一方、Linux上で動作するJavaVMがOOM Killerでkillされた場合、同じオプションを指定していてもヒープダンプは出力されない。 以下のよ…

Downsides of JSR-303 Bean Validation

No guarantee of the order of validation in one field No guarantee of the order of fields to be validated No guarantee of the order of error messages Can't use the result of validation in business logic e.g. it will become a bottleneck to i…

Output of jcmd GC.heap_dump is placed in the root directory of the application

Problem When you get a heap dump of a Java application with jcmd like: PS C:\home\satob> jcmd 18228 GC.heap_dump ./demo.hprof 18228: Heap dump file created You will not be able to find the heap dump on the current directory like: PS C:\hom…

Parasoft DTPでソースの変更点にだけ静的解析をかける方法

ソースの変更点にだけ静的解析をかける機能ってないのかな?と思っていたんですが、あるんですね。 parasoft.techmatrix.jp ただし、ソースコードはGitリポジトリ上に格納されている必要あり。リポジトリの場所の指定方法は以下でいいのかな? docs.parasoft…

Parasoft DTPで指摘を抑止するコメントの構文

Parasoft DTP Engine 10.3.3だと// parasoft-suppress ALLというスタイルのコメント*1以外に、/* parasoft suppress item * line 10 */というスタイルのコメント*2がマニュアルに書いてある。 ところが、Parasoft DTP Engine 10.4.1だと// parasoft-suppress…

Get a deep copy of an object with non-serializable fields with Jackson

Background When you want to get a deep copy of an object, you can use ObjectOutputStream/ObjectInputStream and serialize/deserialize the target object *1 ((Note that SerializationUtils.clone() in Spring Framework requires the class of the …

姓名の分割が行える形態素解析器

前提 姓・名にJIS第1・第2水準外の文字が含まれている日本人はどれくらいの割合でいるか?を調べるときのサンプルとして、国会議員名簿が都合がいい(PCで表示できない文字はその旨書いておいてくれているから)。 問題 姓名が区切りなしで書かれている場合…

Vulnerabilities/Troubles in the Java applications on OWASP Vulnerable Web Applications Directory

# Category Problem EasyBuggy OWASP VulnerableApp OWASP Security Shepherd Vulnerable Java Web Application OWASP WebGoat 1 Troubles Memory Leak (Java heap space) ✓ 2 Memory Leak (PermGen space) ✓ 3 Memory Leak (C heap space) ✓ 4 Deadlock (Ja…

Difference of way to get Java version at runtime

# JDK Way to launch SourceVersion.latestSupported() Runtime.class.getPackage().getImplementationVersion() Runtime.version() System.getProperty("java.version") System.getProperty("java.specification.version") 1 JDK8 java RELEASE_8 1.8.0_312…

ファイルダウンロードを中断すると何が起こるか

Spring Boot 2.7.0で組み込みTomcatでアプリケーションを起動した場合、ファイルダウンロードがブラウザから中断(キャンセル)されるとClientAbortExceptionが発生する。 以前はSocketExceptionが発生していたように思うのですが、Servletコンテナによって…

Merits-demerits of password hashing methods with Java SE / Spring Security API

# Method PBKDF2 bcrypt scrypt Argon2 1 Implementation SecretKeyFactory(PBKDF2WithHmacSHA256) BCryptPasswordEncoder SCryptPasswordEncoder Argon2PasswordEncoder 2 prerequisites JDK 8 or later Spring Security*1 Spring Security + Bouncy Castle…

JDBCドライバがサーバとの1回の通信で取得する行数のデフォルト値

Oracle 11.2は10行。*1 By default, when Oracle JDBC runs a query, it retrieves a result set of 10 rows at a time from the database cursor. This is the default Oracle row fetch size value. Oracle 21は10行。*2 By default, when Oracle JDBC run…

JaCoCoのデータから行単位のbranch coverage (C1 coverage)は復元できない

JaCoCoはC1 Coverageが取れると言っておきながら実際に取れるのはC1(分岐網羅)でなくC2(条件網羅)という問題がある。 この問題に対して、JaCoCo組込みのReportGeneratorを改造するか、またはReportGeneratorを改造するかして、コードカバレッジのデータ…

Java用SSHクライアントライブラリの比較

背景 JavaによるOLTP処理の中で、「別サーバのauthorized_keysに指定されたコマンドをパスフレーズなしのSSH鍵でキックし、その戻り値を確認する」という処理を行いたい場合、外部コマンドとしてSSHを起動するのはいかにも手間がかかる。 そこで、Javaで実装…

C argv[0] equivalent for Java

In C, you can get the name of the binary file called from the shell with argv[0]. In Java, it seems there is no obvious way to get the equivalent: the name of the class that has the entry-point main() class. I made three options, but none …

各種ツールのJava 17への対応状況

Antには、コンパイル環境のJavaバージョンを判定・取得するJavaEnvUtilsというクラスがあるが、このクラスは最新の1.10.12でもJava 12までしか定義がない。 https://github.com/apache/ant/blob/master/src/main/org/apache/tools/ant/util/JavaEnvUtils.jav…

ツールごとのC1カバレッジ取得方法比較

Java ReportGeneratorでは、分岐カバー率50%を超える行は緑色で表示されてしまい、条件網羅を記録するJaCoCoのようなツールでは逆に表示が分かりにくいという問題があることが分かったので、JaCoCoはEclipseの画面をそのまま表示。 JaCoCoはバイトコード単位…

OpenCloverでC1カバレッジが取れるか?

結論 JaCoCoでは行単位のC1カバレッジが取れないのだ、OpenCloverでは行単位のC1カバレッジが取れそう。C1が100%実行されていないのに100%と表示されてしまうといった問題もなさそう。 手順 手元の環境ではなぜかEclipseでOpenCloverを使う手順が上手く動か…

PleiadesのTomcatにEclipseからアプリをデプロイした際の確認先

EclipseからTomcatにアプリをデプロイしたんだけど、思った通りに動いていないように見える……ちゃんとデプロイされてるんだっけ?などというときに調べるフォルダ。 アプリケーションの展開先 (Eclipseのワークスペース)/.metadata/.plugins/org.eclipse.wst…

Spring Frameworkのmax-file-sizeによるアップロードファイルサイズ制限のまとめ

satob.hatenablog.com application.propertiesにspring.servlet.multipart.max-file-size=100のように設定することでサイズ制限設定可能。 Spring Frameworkのファイルアップロード機能は、Webコンテナが持っているmultipartリクエストの処理機能をそのまま…

Spring Frameworkのアップロードファイルサイズ制限のテスト

spring.servlet.multipart.max-file-size=100を設定した状態で、以下のようなControllerに様々なmultipart/form-dataリクエストを送信して結果を比較した。 @PostMapping("/upload") public String handleFileUpload(@RequestParam("file") MultipartFile fi…

Validate memory consumption in a JUnit test case

For load test If you want to run a load test in a JUnit test case and get maximum memory consumption or GC count as a Java variable, the way to do it doesn't seem to be. For memory consumption of whole Java VM If you want to run some tests…

マークアップ言語に対する静的解析

JSPやXMLなどのマークアップ言語に対して、たとえば JSPで<form:password>タグのshowPassword属性はtrueにしたらダメ JETTでxlsxファイルに<jt:comment>タグは使ったらダメ Apache FOPで<fo:external-graphic>タグのsrc属性に#や%や空白が入っていたらダメ myBatisのMapper XMLでLEFT OUTER JOINのOUTERを省略</fo:external-graphic></jt:comment></form:password>…

JavaEEアプリケーションサーバに対するHTTPリクエストの流量制御が可能な箇所の候補

RHEL標準の機能のみで、外から追加のモジュール等を導入することなしに採用可能な方法の候補を列挙してみた。また商用JavaEEサーバの場合は専用の機能があるケースもありそうだが、Tomcatの場合に使える方法の候補も調べてみた。 制御箇所の候補 TCP/IPレベ…

Javaアプリケーションサーバのライセンスに関する考察

GlassFishはEPL 2.0とGPLv2のデュアルライセンスである。ここで、GPLv2にはクラスパス例外が付いている*1。わざわざクラスパス例外が付いているってことは、「クラスパス例外が付いていないGPLのJavaアプリケーションサーバでは、その上で動かすプログラムも…

ProcessBuilder freezes when you try to run a .bat containing PowerShell scripts

Background By using the .bat file from here, you can run a PowerShell script by just click the .bat file. reosablo.hatenablog.jp Problem When you are trying to run the .bat file from Java ProcessBuilder class like this, the .bat file will …

Equivalent of native2ascii and native2ascii -reverse in CyberChef

CyberChef Unescape string is equivalent to native2ascii -reverse. CyberChef Escape string is almost equivalent to native2ascii. Escape level should be "Special chars". native2ascii never escape Escape single quotes, double quotes, or backt…